c# - Castle Windsor - Get Root Component type being resolved -


i using castle windsor ioc container , nlog in project. trying inject ilogger classes logging needed. want ilogger resolved logmanager.getlogger(roottypename).

is there way root type name? tried following, creationcontext.requestedtype doesnt root type.

container.register(component.for<ilogger>()     .usingfactorymethod((y, creationcontext) =>         logmanager.getlogger(creationcontext.requestedtype.fullname))     .lifestyletransient()); 

structuremap has provision it

x.for<logger>().use(y => logmanager.getlogger(y.roottype.fullname)); 

you can achieve subresolver...

public class loggerresolver : isubdependencyresolver {     public bool canresolve(creationcontext context, isubdependencyresolver contexthandlerresolver, componentmodel model, dependencymodel dependency)     {         return dependency.targettype == typeof(ilogger);     }      public object resolve(creationcontext context, isubdependencyresolver contexthandlerresolver, componentmodel model, dependencymodel dependency)     {         return new logmanager.getlogger(model.implementation.fullname);     } } 

than add kernel,

kernel.resolver.addsubresolver(new loggerresolver()) 

and drop previous ilogger registration.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -