AddComponentInstance:
WindsorContainer.Kernel.AddComponentInstance<T>(typeof(T), instance);
已过时。
它的替代品是:
WindsorContainer.Register(Component.For<IClassParameters>().ImplementedBy<ClassParameters>());
但是我有一个门面:
public static void AddInstance<T>(object instance)
{
_iocManager.WindsorContainer.Kernel.AddComponentInstance<T>(typeof(T), instance);
}
我看不到如何使用Register方法而不是AddComponentInstance 这是错的:
_iocManager.WindsorContainer.Register(Component.For<T>().ImplementedBy<T>().Instance(instance));
我应该使用什么?
答案 0 :(得分:1)
答案是:
public static void AddInstance<T>(T instance) where T : class
{
_iocManager.WindsorContainer.Register(Component.For<T>().Instance(instance));
}
请注意方法签名,强制编译器将T作为Class,因此作为Ref变量
答案 1 :(得分:-1)
container.Register(Component.For<Foo>().Instance(new Foo());