I use the following service registration in .NET ASP:

kernel.Bind<IService>().To<Service>(); 

after getting the service in the controller.

I know that when registering a service in .NET ASP Core, you can use different methods of the standard IOC container (AddScoped, AddSingleton, AddTransient) and this will affect how the service is received in the controller.

Does this Ninject method create a new service each time (like AddTransient)? If this can be customized it would be interesting to know how.

  • If you read about the life cycle of dependencies , then you probably also saw a simple example of how to define dependencies in a different way. It's simple: we create some service that returns random numbers and instantiate it in different ways. You can be given a ready-made answer - but you can understand it much deeper if you try to create an example and try it yourself. This will give the most important skill in programming: the ability to independently acquire knowledge, and not copy-paste with so. Try it, it is not very difficult. - AK
  • 3

1 answer 1

As a rule, popular libraries are well documented.

Ninject is just one of them, and as a result, the first thing to do is to refer to the documentation , then google it and if there are still questions, ask a question.

It was a small lyrical digression, and now to the point.

If you turn to a specific section of the documentation , the behavior settings are described there:

  • Transient - created every time
  • Singleton - created once
  • Thread - created for each thread
  • Request - created for each request
  • Named , Call , Parent - flexible behavior setting
  • Custom - custom behavior