How to register a shared service

I plan to move my system to a general service level.

public interface IAbcService<TEntity> where TEntity : class public class AbcService<TEntity> : IAbcService<TEntity> where TEntity : class 

I tried something, but it does not work.

 services.AddTransient<typeof(IAbcService<MyEntity>), AbcService(); .... .... .... 

I use some of my entities, and with this I try to add it to properties.

How can I register a shared service in the asp.net core?

+5
source share
2 answers

I wanted to try the same thing before, and it worked out like this:

 services.AddTransient(typeof(IAbcService<>), typeof(AbcService<>)); services.AddTransient(typeof(IAbcService<Person>), typeof(AbcService<Person>)); 

Separate a different structure, this is recorded by the parameters in the method.

To develop, as you can see in the above example, a new DNX infrastructure package, we can now register both open and closed generics. Try it, both lines will work.

+7
source

You tried

services.AddTransient <IAbcService <>, AbcService> ()

-2
source

Source: https://habr.com/ru/post/1242400/


All Articles