I have a centralized StructureMap configuration that various user interface applications append to. I have never had the need to modify the "core" configuration only append to it. I've run into an instance today where I need to modify / remove the core configuration for a particular application. Of course I could move the core configuration code out to the different application, but before I do so I wanted to be sure I was not missing something obvious with the StructureMap api. Below is an abbreviated version of my core configuration:
ObjectFactory.Initialize(cfg =>
{
cfg.Scan(scan =>
{
scan.Assembly("Core");
scan.WithDefaultConventions();
scan.ConnectImplementationsToTypesClosing(typeof(IValidationRule<>));
// more after this....
}
}
At runtime for this one application I would like to remove the configuration for types closing IValidationRule
, but have yet to come up with anything viable. All of the eject methods seem to center around singletons meaning. Since I am not dealing with a singleton the following does not work:
ObjectFactory.Model.For(typeof(IValidationRule<>)).EjectAndRemoveAll(); //no work
ObjectFactory.Model.EjectAndRemove(typeof(IValidationRule<>)); //nor does this
Is there a way that I can modify my StructureMap configuration to not look for IValidationRule
s? Can I eject non-singleton instances of IValidationRule
s? Do I have other options for modifying my StructureMap configuration?
What about something like the following? I think this should work.
ObjectFactory.Model.EjectAndRemoveTypes(match
=> match != null && match.GetInterfaces().Any(i
=> i.Name.Contains("IValidationRule")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With