c# - Is it possible to remove an existing registration from Autofac container builder? -


something along lines:

builder.registertype<mytype>().as<itype>(); builder.registertype<mytype2>().as<itype>(); builder.deregistertype<mytype>().as<itype>()  var container = builder.build(); var types = container.resolve<ienumerable<itype>>(); assert.istrue(types.count == 1); assert.istrue(types[0].gettype == typeof(mytype2)); 

scenario: go through bunch of assemblies , go register types want make sure have 1 implementation of given type. need before create container. track on own nice if autofac me bit.

this cannot done directly using containerbuilder, unless start on new one. mind you, having first built container should able construct new container filtering away unwanted types , reusing registrations first container. this:

... var container = builder.build();  builder = new containerbuilder(); var components = container.componentregistry.registrations                     .where(cr => cr.activator.limittype != typeof(lifetimescope))                     .where(cr => cr.activator.limittype != typeof(mytype)); foreach (var c in components) {     builder.registercomponent(c); }  foreach (var source in c.componentregistry.sources) {     cb.registersource(source); }  container = builder.build(); 

this hardly elegant works. now, if elaborate on why want this, perhaps there better way.


Comments

Popular posts from this blog

Javascript line number mapping -

linux - Mailx and Gmail nss config dir -