0

Hello i am working with an asp.net webapi program. i am trying to use simple injector.

i can init and register types in application start . but I have a question:

how to get container instance to resolve object?

Some classes are provided by 3rd party and cannot register. And if I cannot get container instance, then what's the meaning of

    using (Scope scope = AsyncScopedLifestyle.BeginScope(container))
{
    var service = container.GetInstance<IOrderShipmentProcessor>();

    service.ProcessShipment();
}

as I cannot provide container parameters?

2
  • In general, you shouldn't get a container. That's called service locator pattern, and it's generally to be avoided. What real world situation do you have where you think you need it?
    – mason
    May 18, 2022 at 3:07
  • Can you provide us with more context? "how to get the container" is really depending on the situation, so can you update your question and demonstrate (preferably with concrete code examples) how, where, and why you need to have access to the container object? And what type of application are you building? Is this a Console, Win Forms, Windows Service, ASP.NET classic Web Forms, MVC, or Web API, ASP.NET Core application, or something else? Did you look at the integration guide?
    – Steven
    May 18, 2022 at 6:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.