10

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
superjos
  • 11,549
  • 5
  • 84
  • 127
jkruer01
  • 2,115
  • 4
  • 31
  • 56

1 Answers1

9

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

Dave Thieben
  • 5,348
  • 2
  • 27
  • 37
Kiran
  • 55,421
  • 15
  • 173
  • 154