Injecting a primitive property in a base class with Castle Windsor

后端 未结 1 1102
生来不讨喜
生来不讨喜 2020-12-19 19:08

I have got the following interface definition:

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


        
相关标签:
1条回答
  • 2020-12-19 19:33
    .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.

    0 讨论(0)
提交回复
热议问题