There is currently no support for using a factory with an open generic type. There's an open issue on GitHub discussing this:
Dependency Injection of Open Generics via factory · Issue #41050 · dotnet/runtime · GitHub[
^]
I'd suggest using another class to inject the parameter into your constructor. For example:
public class MyContextOptions
{
public MyContextOptions(string value)
{
Value = value;
}
public string Value { get; }
}
public partial class MyContext<TEntity> : IMyContext<TEntity> where TEntity : class
{
public MyContext(MyContextOptions options)
{
}
}
services.AddSingleton(new MyContextOptions("connection"));
services.AddScoped(typeof(IMyContext<>), typeof(MyContext<>));