Using Asp.Net Core 3 have the following method:
public static void AddLiteContext<TContext, TContextMapper>(this IServiceCollection services, String connection)
where TContext : ILiteContext
where TContextMapper : LiteContextMapper {
}
Inside this method I need to the following:
services.AddTransient<Context>(x => new Context(connection, new ContextMapper()));
But I need to create the instances of Context and ContextMapper based on the generics:
ILiteContext
LiteContextMapper
Note that class Context and class ContextMapper are implementations of these generics:
public class Context : ILiteContext { }
public class ContextMapper : LiteContextMapper { }
I use the method as follows:
services.AddLiteContext<Context, ContextMapper>(myConnection);
How can I do this?