SimpleInjector is an open-source lightweight dependency injection container for .NET applications that provides a simple API for registering dependencies and resolving them by injecting them into constructors or properties.
Example 1: Registering a singleton instance of a type:
var container = new Container();
container.Register(Lifestyle.Singleton);
This code creates a new container object and registers a singleton instance of MyService using the Lifestyle.Singleton configuration. This means that only one instance of MyService is created and reused by the container for the lifetime of the application.
Example 2: Registering an implementation for a generic interface:
This code registers an implementation of IRepository with MyRepository using the container's Register method. This is useful if you have several types of repositories that implement the same interface.
Package library: SimpleInjector can be downloaded as a NuGet package from the NuGet Gallery. The package name is "SimpleInjector".
C# (CSharp) SimpleInjector Container - 60 examples found. These are the top rated real world C# (CSharp) examples of SimpleInjector.Container extracted from open source projects. You can rate examples to help us improve the quality of examples.