Where & How Castle Windsor sets up logging facility

前端 未结 3 1101
慢半拍i
慢半拍i 2020-12-28 10:12

I\'m fairly new to Castle Windsor and am looking into the in\'s and out\'s of the logging facility. It seems fairly impressive but the only thing i can\'t work out is where

3条回答
  •  [愿得一人]
    2020-12-28 10:44

    Since you have a public Property with a Setter, every time you resolve your object from Windsor, it will also try to set any public properties with appropriate values from the container (in your case, an ILogger which your facility will populate into Windsor).

    Meaning, if you resolve the Class from Windsor, this will be set. But not if you do new Class().

    That's atleast how I understand it.

    The other approach is to use constructors, meaning if you have a constructor named

    public Class(ILogger logger) it will be instantiated with ILogger as a parameter.

    Example:

    
    var yourClassObject = Kernel.Resolve();
    
    

    IF you don't have an interface specification (and registered as such), you will need to register your component as the concrete type if you want to resolve it using that concrete type(and not by interface).

提交回复
热议问题