Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:06:13+00:00 2026-06-17T22:06:13+00:00

In my bootstrapper: namespace Conduit.Mam.ClientServices.Common.Initizliaer { public static class Initializer { private static bool

  • 0

In my bootstrapper:

namespace Conduit.Mam.ClientServices.Common.Initizliaer
{
    public static class Initializer
    {
        private static bool isInitialize;
        private static readonly object LockObj = new object();
        private static IUnityContainer defaultContainer = new UnityContainer();

        static Initializer()
        {
            Initialize();
        }

        public static void Initialize()
        {
            if (isInitialize)
                return;

            lock (LockObj)
            {
                IUnityContainer container = defaultContainer;

                //registering Unity for MVC
                DependencyResolver.SetResolver(new UnityDependencyResolver(container));

                //registering Unity for web API
                //  GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);

                #region managers
                container.RegisterType<ISettingsManager, SettingsManager>();

                container.RegisterType<IMamDataManager, MamDataManager>();

                container.RegisterType<IAppsDataManager, AppsDataManager>();
                #endregion

                if (!isInitialize)
                {
                    isInitialize = true;
                }
            }
        }
    }
}

in my controller’s code:

ISettingsManager sm = mUnityContainer.Resolve<ISettingsManager>();

hovering on mUnityContainer I see ISettingsManager is mapped to SettingsManager

but then I get the error:

Exception is: InvalidOperationException – The current type, is an
interface and cannot be constructed. Are you missing a type mapping?

I have also tried

ISettingsManager sm = (ISettingsManager)mUnityContainer.Resolve<>(typeof(ISettingsManager));

but no use

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:06:14+00:00Added an answer on June 17, 2026 at 10:06 pm

    You are incorrectly using Dependency Injection. The proper way is to have your controllers take the dependencies they need and leave to the dependency injection framework inject the concrete instances:

    public class HomeController: Controller
    {
        private readonly ISettingsManager settingsManager;
        public HomeController(ISettingsManager settingsManager)
        {
            this.settingsManager = settingsManager;
        }
    
        public ActionResult Index()
        {
            // you could use the this.settingsManager here
        }
    }
    

    As you can see in this example the controller doesn’t know anything about the container. And that’s how it should be.

    All the DI wiring should happen in your Bootstraper. You should never use container.Resolve<> calls in your code.

    As far as your error is concerned, probably the mUnityContainer you are using inside your controller is not the same instance as the one constructed in your Bootstraper. But since you shouldn’t be using any container code in your controllers, this shouldn’t be a problem anymore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my bootstrapper I start by doing this: public static void Initialise() { var
I have set up a bootstrapper as follows: private static IUnityContainer BuildUnityContainer() { var
Our installer generates a bootstrapper (setup.exe) and a MSI file - a pretty common
I 'm using PRISM and in the Bootstrapper class i did override the ConfigureContainer()
I'm using the Unity IoC framework and have a Bootstrapper.cs class in my host
I have some questions regarding a bootstrapper class. I am using ASP.NET MVC 3
I have an ASP.NET MVC app which has a bootstrapper class that configures log4net
So I've refactored completely to constructor injection, and now I have a bootstrapper class
I use standart NinjectMVC3 Bootstrapper installed in the App_Start folder. My application class looks
I am using a Prism UnityExtensions bootstrapper class to start my WPF application. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.