Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify a previously configured StructureMap configuration?

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 IValidationRules? Can I eject non-singleton instances of IValidationRules? Do I have other options for modifying my StructureMap configuration?

like image 987
ahsteele Avatar asked Nov 04 '22 09:11

ahsteele


1 Answers

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")));
like image 168
Jake Avatar answered Nov 14 '22 02:11

Jake