在温莎城堡的一个基类注射一种原始的属性城堡、属性、原始、温莎

2023-09-04 00:46:31 作者:三个人的爱情。

我有以下的接口定义:

 公共接口ICommandHandler
{
    ILogger记录器{获得;组; }
    布尔SendAsync {获得;组; }
}
 

我有一个执行 ICommandHandler 和需要解决的多种实现。虽然城堡的Windows自动注入的日志属性,当 ILogger 注入,我无法找到一个方法来配置在 SendAsync 属性来创造新的时间期间被设置为true温莎。

更新的

命令处理程序实现一个通用的接口,继承了基接口:

 公共接口ICommandHandler< TCommand> :ICommandHandler
    其中,TCommand:命令
{
     无效手柄(TCommand命令);
}
 

下面是我的配置:

  VAR集装箱=​​新WindsorContainer();

container.Register(组件
     。对于< ICommandHandler< CustomerMovedCommand>>()
     .ImplementedBy&其中; CustomerMovedHandler>());
container.Register(组件
     。对于< ICommandHandler< ProcessOrderCommand>>()
     .ImplementedBy&其中; ProcessOrderHandler>());
container.Register(组件
     。对于< ICommandHandler< CustomerLeftCommand>>()
     .ImplementedBy&其中; CustomerLeftHandler>());
 
持弩爬围栏 19岁男子闯英女王城堡被捕

在那里与温莎城堡做到这一点的方法是什么?

解决方案

  .DependsOn(临prerty.ForKey(sendAsync)。方程(真))
 

或匿名类型

  .DependsOn(新{sendAsync = TRUE})
 

有关更新的问题,这seeems你需要的是大致如下:

  container.Register(AllTypes.FromThisAssembly()
   .BasedOn(typeof运算(ICommandHandler<>))
   .WithService.Base()
   .Configure(C => c.DependsOn(新{sendAsync = TRUE})
                    .Lifestyle.Transient));
 

这样,你注册和配置所有的处理程序一气呵成,而当你添加新的,你不会要回去把它们添加到报名code。

我建议通过文档 阅读的还有更多的公约为基础的比这个注册API。

I have got the following interface definition:

public interface ICommandHandler
{
    ILogger Logger { get; set; }
    bool SendAsync { get; set; }
}

I have multiple implementations that implement ICommandHandler and need to be resolved. While Castle Windows automatically injects the Logger property, when an ILogger is injected, I can't find a way to configure the SendAsync property to be set to true by Windsor during the creation of new instances.

UPDATE

The command handlers implement a generic interface that inherits from the base interface:

public interface ICommandHandler<TCommand> : ICommandHandler
    where TCommand : Command
{
     void Handle(TCommand command);
}

Here is my configuration:

var container = new WindsorContainer();

container.Register(Component
     .For<ICommandHandler<CustomerMovedCommand>>()
     .ImplementedBy<CustomerMovedHandler>());
container.Register(Component
     .For<ICommandHandler<ProcessOrderCommand>>()
     .ImplementedBy<ProcessOrderHandler>());
container.Register(Component
     .For<ICommandHandler<CustomerLeftCommand>>()
     .ImplementedBy<CustomerLeftHandler>());

What ways are there to do this with Castle Windsor?

解决方案

.DependsOn(Proprerty.ForKey("sendAsync").Eq(true))

or with anonymous type

.DependsOn(new{ sendAsync = true })

regarding updated question, it seeems what you need is along the following lines:

container.Register(AllTypes.FromThisAssembly()
   .BasedOn(typeof(ICommandHandler<>))
   .WithService.Base()
   .Configure(c => c.DependsOn(new{ sendAsync = true })
                    .Lifestyle.Transient));

That way you register and configure all handlers in one go, and as you add new ones you won't have to go back to add them to registration code.

I suggest reading through the documentation as there's much more to the convention-based registration API than this.

 
精彩推荐
图片推荐