3

As we all know In asp.net Startup class there is a method ConfigureServices we can add custom Services. Services are made available through Dependency Injection.

ASP.NET Core includes a simple built-in inversion of control (IoC) container that supports constructor injection by default, but can be easily replaced with your IoC container of choice. In addition to its loose coupling benefit, DI makes services available throughout your app

My Question is how to Replace Built in IoC with my Own IoC?

Please provide me an example if you have.

alamin
  • 2,377
  • 1
  • 26
  • 31

1 Answers1

7

There are a number of different containers currently available for ASP.NET Core, including

Exactly how you use them differs in each case, but essentially they all follow the same pattern:

  • Register dependencies as usual using the built-in container
  • Create an instance of your third-party Container
  • Add any additional registrations to your third-party container
  • Populate the new container with registrations from the built-in container
  • Return an IServiceProvider from your third-party container

It might be worth taking note that there are a number of conversations happening around the way these libraries will integrate with the built in container going forward. The comment here provides a good summary of the conversation, or you can dive right into the discussions on GitHub here and here.

Community
  • 1
  • 1
Sock
  • 5,323
  • 1
  • 21
  • 32
  • "but essentially they all follow the same pattern". This is not the case for Simple Injector as described in the referenced integration page. Simple Injector runs side-by-side with the built-in container. – Steven May 20 '21 at 08:51