c# - Find out which module registered type -


i'm debugging autofac issues in application quite lot of modules. there way find out module registered registration? i'm looking @ componentregistry of container, can't find information there.

edit: clarification. have lot of modules in solution:

public class mymodule : autofac.module {     public override void load(containerbuilder builder) {         builder.registertype<myconcretetype>().as<imyinterface>();     } } 

i register in container scanning assemblies:

var builder = new containerbuilder(); builder.registerassemblymodules(/* assemblies in base dir */); var container = builder.build(); 

now, have lot of registrations. question "what module registered myconcretetype?". container.componentregistry.registrations.select(reg => new { reg.service, reg.registeredby }), registeredby magic property.

ok, not 100% sure mean, i'll give go:

for debugging, implemented type displayed in registrations collection of componentregistry:

enter image description here

i.e. @ index 0, implementation type customdataelement.

as service type implementation type registered can seen in componentregistrations services collection.

does help? can give example otherwise?

edit:

got it... try this:

var l = _container.componentregistry.registrations     .selectmany(r => r.services.oftype<iservicewithtype>(),                 (r, s) => new { r.activator.limittype, s.servicetype }); 

not sure whether works 100% expected, should there...

edit 2:

i misunderstood question, didn't distinguish between registered service , registering module. don't think possible out of box, either require passing module argument or autofac reflect caller upon registration. both not case, far can tell. can't find built in features in autofac.

if can modify modules, 1 approach register types metadata. know approach, like

public class mymodule: autofac.module {     public override void load(containerbuilder builder)      {         builder.registertype<myconcretetype>()                .as<imyinterface>()                .withmetadata<iregisteredbymodulemetadata>(m =>                     m.for(am => am.registeringmoduletype, gettype());;     } } 

with metadata interface

public interface iregisteredbymodulemetadata {     type registeringmoduletype { get; set; } } 

then in container, resolving metadata allow access module types via registrations metadata property. depending on requirements simplify type registration providing protected type registration method on custom module base class automatically appends metadata, don't have repeat here.

if modifying every module in solution option, that's not bad way go. sorry can't give out-of-the-box solution. there might one, missing, that's can here. hope helps nonetheless.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -