使用Asp.Net Core 3具有以下方法:
public static void AddLiteContext<TContext, TContextMapper>(this IServiceCollection services, String connection)
where TContext : ILiteContext
where TContextMapper : LiteContextMapper {
}
在此方法中,我需要执行以下操作:
services.AddTransient<Context>(x => new Context(connection, new ContextMapper()));
但是我需要基于泛型创建Context和ContextMapper的实例:
ILiteContext
LiteContextMapper
请注意,Context类和ContextMapper类是这些泛型的实现:
public class Context : ILiteContext { }
public class ContextMapper : LiteContextMapper { }
我使用以下方法:
services.AddLiteContext<Context, ContextMapper>(myConnection);
我该怎么做?