Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
301 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...