IKernel.Bind is a method provided by the Ninject dependency injection library in C#. This method allows the registration of services and their implementations with the Ninject kernel, so that the implementations can be injected into objects that require the services.
One example of using IKernel.Bind is to bind a service interface to a concrete implementation. For instance, suppose we have an interface ILoggingService and a class FileLoggingService that implements it. We can use IKernel.Bind to make the FileLoggingService the implementation of ILoggingService:
kernel.Bind().To();
Another example is to bind a service to a factory method that produces the implementation. Suppose we have a class DatabaseService that requires an instance of IDbConnection to operate, and we want to create a new IDbConnection for each DatabaseService instance. We can use IKernel.Bind with a lambda expression to produce a new IDbConnection whenever it is needed:
kernel.Bind().ToMethod(ctx => CreateDbConnection());
kernel.Bind().ToSelf();
// ...
private IDbConnection CreateDbConnection()
{
// Create a new IDbConnection
}
The package library for Ninject is "Ninject".
C# (CSharp) IKernel.Bind - 60 examples found. These are the top rated real world C# (CSharp) examples of IKernel.Bind extracted from open source projects. You can rate examples to help us improve the quality of examples.