我有以下这个类:
public class DatabaseFactory<C> : Disposable, IDatabaseFactory<C> where C : DbContext, BaseContext, new()
{
private C dataContext;
private string connectionString;
public DatabaseFactory(string connectionString)
{
this.connectionString = connectionString;
}
public C Get()
{
return dataContext ?? (dataContext = Activator.CreateInstance(typeof(C), new object[] {connectionString}) as C);
}
protected override void DisposeCore()
{
if (dataContext != null)
dataContext.Dispose();
}
}
当我尝试启动Web API时,出现以下错误:
无法创建组件'MyApp.DAL.Implementations.DatabaseFactory'1',因为它具有需要满足的依赖项。 'MyApp.DAL.Implementations.DatabaseFactory'1'正在等待以下依赖项:
-未提供参数“connectionString”。您是否忘记设置该依赖项?
我应该如何正确注册它,并在运行时如何传递参数?