【发布时间】:2019-08-12 07:12:26
【问题描述】:
我必须创建一些带有按需控制的对象来刷新它。
我在 LightInject 中有代码
public Lifetime()
{
lifetimes = new List<Flushable>();
}
public Lifetime Create()
{
var lifetime = new Flushable();
lifetimes.Add(lifetime);
return lifetime;
}
public void Flush()
{
foreach (var lifetime in lifetimes)
{
lifetime.Flush();
}
}
在 DI 代码中
var life = new Lifetime();
container.RegisterInstance<ILifetime>(life);
container.Register<SomeCache>(life.Create());
我想把上面的代码移到.net core DI
.netcore Di 有可能吗
【问题讨论】:
-
您已经用相同的标题询问了a question。试着让你的问题的标题更具体。
标签: c# asp.net-core dependency-injection