Home > Blockchain >  IOC in .NET CORE
IOC in .NET CORE

Time:12-01

What type of IoC is used for AddSingleton , AddScoped or AddTransient in Asp.NET Core? is it Unity, Spring.Net or Ninject ? or something Build in specialy for .NET Core.

Thanks,

CodePudding user response:

Depends what you add to the project.

The project templates that include a DI container typically include Microsoft.Extensions.DependencyInjection and instantiate the container that provided.

However you can bring your own. Sometimes you build in the same way and use that to initialise that third party containr. For instance with AutoFaq it can import the ServicesContainer instance from MS's library to initialise its content.

CodePudding user response:

.NET core uses a built in IoC container. It is not unity by default. But you can bring in third party containers with much more advanced features than the built in container. Some examples include - Scrutor, AutoFac, Unity etc. The built-in IoC container supports three kinds of lifetimes:

  1. Singleton: IoC container will create and share a single instance of a service throughout the application's lifetime.
  2. Transient: The IoC container will create a new instance of the specified service type every time you ask for it.
  3. Scoped: IoC container will create an instance of the specified service type once per request and will be shared in a single request.
  • Related