与温莎城堡泛型类型约束解析接口 [英] Resolving Interface with generic type constraint with Castle Windsor
本文介绍了与温莎城堡泛型类型约束解析接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public interface IFooHandler<TRequest, TResponse> where TRequest : FooRequest where TResponse : FooResponse
{
TResponse CheckFoo(TRequest request);
}
的实现:
An implementation of:
public class MyFooHandler : IFooHandler<MyFooRequest, MyFooResponse>
{
public MyFooResponse CheckFoo(MyFooRequest request)
{
/* check for foos */
}
}
我怎么会在温莎城堡登记本,所以我可以使用(其中IoCContainer是WindsorContainer解决问题
How would I register this in Castle Windsor so I can resolve it using (where IoCContainer is a WindsorContainer:
Global.IoCContainer.Resolve<IFooHandler<FooRequest, FooResponse>>();
要解决MyFooHandler?
to resolve an instance of MyFooHandler?
推荐答案
的实例,在温莎城堡,您可以使用这样的代码:
In Castle Windsor you can use such code :
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For(typeof(IRepository<>)).ImplementedBy(typeof(Repository<>))
}
);
public class Repository<T> : IRepository<T> where T : class, IEntity
{
...
}
所以我发现登记和解决仿制药注册和使用的接口解决仿制药很简单。有很多的城堡和周围的仿制药的问题。
Therefore I find registering and resolving generics pretty simple for registering and resolving generics with interfaces. There a lots of questions on castle and generics around.
这篇关于与温莎城堡泛型类型约束解析接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文