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 8362039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:50:56+00:00 2026-06-09T11:50:56+00:00

I am in the process of migrating from StructureMap to Simple Injector in a

  • 0

I am in the process of migrating from StructureMap to Simple Injector in a ASP.NET MVC3 application.

I am using the MVC3 extension for controller DI, but I am running into an issue with trying to replace the static aspects of StructureMap. We have calls to

StructureMap.ObjectFactory.GetInstance<Interface>()

throughout different layers of the app. It does not look like Simple Injector has a way to do that.

Am I missing something? Or is Simple Injector not applicable for my application?

Please advise and thanks in advance.

  • 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-09T11:50:58+00:00Added an answer on June 9, 2026 at 11:50 am

    Allowing the application to directly access the container is considered to be bad practice. It is an form of the Service Locator anti-pattern.

    Because this is considered to be a bad thing, Simple Injector does not contain anything like StructureMap’s ObjectFactory.GetInstance. And as a matter of fact, the author of StructureMap is considering the removal of the ObjectFactory API in a furure release of StructureMap.

    However, nothing stops you from storing the SimpleInjector.Container instance in a static field and let the application use this:

    // Service Locator implementation in low application layer.
    public static class ObjectFactory
    {
        private static SimpleInjector.Container container;
        
        public static void SetContainer(Container container)
        {
            ObjectFactory.container = container;
        }
        
        public static T GetInstance<T>() where T : class
        {
            return container.GetInstance<T>();
        }
    }
    

    In Composition root:

    public static void Initialize()
    {
       var container = new Container();      
    
       InitializeContainer(container);
       
       DependencyResolver.SetResolver(
            new SimpleInjectorDependencyResolver(container));   
    
       // Set the service locator here
       ObjectFactory.SetContainer(container);
    }
    

    So there is no limitation in the Simple Injector that prevents you from doing this, but frankly, you are already witnessing one of the reasons why Service Locator is a bad thing: you switched containers and now you have to change application code.

    Perhaps for now it is easiest for you to save the container in a static field (as shown in the example above), but please take the time to understand why this pattern is bad, and do refactor away from this pattern towards dependency injection (and especially constructor injection).

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

Sidebar

Related Questions

We are in the process of migrating an ASP Classic/ASP.NET application from IIS 6
We are in the process of migrating our ASP.NET application to use Jquery instead
I'm in the process of migrating a VB.NET web application from Visual Studio 2005
I'm in the process of moving a large classic ASP application to ASP.NET MVC
I am in the process of migrating an application ( Sage ) from Twisted
I am in the process of migrating an application from django 1.2 To 1.4.
We are currently in the process of migrating our application from our production environment
We are migrating from an ASP.NET/SQL server setup to a rails/mysql setup. Because of
We are in the process of migrating an app to .NET 4.0 (from 3.5).
I'm in the process of migrating portions of an application from Windows Forms to

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.