VNext Dependency Injection Generic Interface

I created the ASP.Net vNext Web API.

I have successfully used dependency induction with a simple interface such as:

services.AddScoped<ILinearRegressionCalculator, LinearRegressionCalculator>(); 

However, I cannot figure out how to make a dependency using a universal interface.

How to configure dependency injection for this interface:

 public interface IMongoConnectionHandler<T> where T : IMongoEntity 
+8
generics c # dependency-injection asp.net-core
source share
1 answer

The following is an example:

services.TryAdd(ServiceDescriptor.Singleton(typeof(IOptions<>), typeof(OptionsManager<>)));

Source: https://github.com/aspnet/Options/blob/1.0.0-rc1/src/Microsoft.Extensions.OptionsModel/OptionsServiceCollectionExtensions.cs#L23

+6
source share

All Articles