[英]Factory facility in Simple Injector
I am migrating from Windsor
to Simple Injector
, I tried to follow the following this link . 我从
Windsor
迁移到Simple Injector
,我尝试遵循以下此链接 。 But I could not find any replacement for: 但是我找不到任何替代品:
container.AddFacility<TypedFactoryFacility>();
container.Register(Component.For<ICacheDependencyFactory>().AsFactory());
What will be the replacement the above code in Simple Injector
? 在
Simple Injector
中将替换上面的代码吗?
Edited: 编辑:
ICacheDependencyFactory.cs ICacheDependencyFactory.cs
public interface ICacheDependencyFactory
{
T Create<T>()
where T : ICacheDependency;
void Release<T>(T cacheDependency)
where T : ICacheDependency;
}
Castle's factory facility is able to generate a proxy class based on the interface you supply. Castle的工厂设施能够根据您提供的接口生成代理类。 This proxy class will call back into the container to request the creation of a new instance of such type.
该代理类将回调到容器中,以请求创建此类新实例。
Simple Injector lacks such feature. 简单喷油器缺乏这种功能。 Simple Injector doesn't implement this, because:
Simple Injector不能实现此目的,因为:
Here's an example: 这是一个例子:
private sealed class CacheDependencyFactory : ICacheDependencyFactory {
public Container Container { get; set; }
public T Create<T>() where T : ICacheDependency, class {
return this.Container.GetInstance<T>();
}
}
This factory can be registered as follows: 该工厂可以注册如下:
container.RegisterSingle<ICacheDependencyFactory>(
new CacheDependencyFactory { Container = container });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.