Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vNext Dependency Injection Generic Interface

I have created an ASP.Net vNext Web API.

I have successfully used the dependency inection with a simple interface such as this:

services.AddScoped<ILinearRegressionCalculator, LinearRegressionCalculator>();

However, I can't figure out how to do dependency inection with a Generic Interface.

How do I setup dependency injection for this interface:

public interface IMongoConnectionHandler<T> where T : IMongoEntity
like image 541
jkruer01 Avatar asked Jun 24 '15 21:06

jkruer01


1 Answers

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

like image 191
Kiran Avatar answered Sep 17 '22 14:09

Kiran