What kernel.Bind <SomeType> () does. ToSelf () do?

I understand the following Ninject registration:

kernel.Bind<ISomeType>().To<SomeTypeImplementation>();

which tells Ninect to execute requests for ISomeType using SomeTypeImplementation .

However, I'm not sure if this is useful.

kernel.Bind<ApplicationDbContext>().ToSelf();

What was suggested to be used from this question: Which ninject binding should I use?

+4
source share
2 answers

This makes ApplicationDbContext "self-binding." If you don’t have an interface for binding, you can bind to the class itself. This is more useful if you add an area to call, for example:

kernel.Bind<ApplicationDbContext>().ToSelf().InRequestScope();

, ApplicationDbContext, , , HTTP-.

, , , ApplicationDbContext, . , , . InRequestScope().

+3

, :

  • .

  • , , .

, , - .

+3

Source: https://habr.com/ru/post/1529275/


All Articles