1

我的解决方案中有一些组件可以根据用户的不同状态在我的系统中处理重定向。这些组件基于抽象类型 RedirectAction 并且正在完成这项工作。

我在系统中有另一个接口,用于监视服务和功能是否正常工作/活动。称为 IStatusCheck。

        container.Register(
            AllTypes.FromThisAssembly()
                .BasedOn<IStatusCheck>()
                .WithServiceBase()
                .LifestyleTransient());

        container.Register(
            AllTypes.FromThisAssembly()
                .BasedOn<RedirectAction>()
                .WithServiceBase()
                .LifestyleTransient());

在我让 RedirectAction 实现 IStatusCheck 以启用对它们的监视之前,这很有效。而且我不知道如何注册才能在两者中检索组件。

ResolveAll<RedirectAction>()
ResolveAll<IStatusCheck>()

请帮帮我。

编辑:

更完整的例子

class Program
{
    static void Main(string[] args)
    {
        var container = new WindsorContainer();

        container.Register(
            AllTypes.FromThisAssembly()
                .BasedOn<IGenericInterface>()
                .WithServiceBase()
                .AllowMultipleMatches());

        Debug.Assert(container.ResolveAll<IGenericInterface>().Count() == 2, "Could not find all IGenericInterface types");

        container.Register(
            AllTypes.FromThisAssembly()
                .BasedOn<SpecificAbstractBase>()
                .WithServices(typeof(SpecificAbstractBase))
                .AllowMultipleMatches());

        var specific = container.ResolveAll<IGenericInterface>().First() as SpecificAbstractBase;

        Debug.Assert(specific != null, "Instance was not of expected type");
        Debug.Assert(container.ResolveAll<IGenericInterface>().Count() == 2, "Could not find all IGenericInterface types");
        Debug.Assert(container.ResolveAll<SpecificAbstractBase>().Count() == 2, "Could not find all SpecificAbstractBase types");
    }
}

public interface IGenericInterface
{
    bool ImAlive { get; }
}

public abstract class SpecificAbstractBase : IGenericInterface
{
    public abstract void DoTheJob();

    public bool ImAlive
    {
        get { return true; }
    }
}

public class SpecificOne : SpecificAbstractBase
{
    public override void DoTheJob() { }
}

public class SpecificTwo : SpecificAbstractBase
{
    public override void DoTheJob() { }
}
4

1 回答 1

0

用于.AllowMultipleMatches()允许将类型用于多个组件。

于 2012-05-29T08:08:06.840 回答