开发者

StructureMap - Configure default type for plugin, but can be overridden?

I have a requirement where I'd like to configure a plugin for an interface to always be a default type, but allow another assembly's configuration of that same plugin always take precedence.

So say I have MyAssembly.dll, which has a registry that sets this up: For<IBar>().Use<BarImpl>();

If a particular client needs a different functionality, I want to drop MyAssembly.CustomerA.dll into the bin folder of the application. Its registry will be similar: For<IBar>().Use<CustomerABarImpl>();

The configuration in in MyAssem开发者_如何学Cbly.CustomerA.dll should ALWAYS override the configuration.

I've read that profiles can do this, but that seems to imply I need to set which profile the application should use. I'd rather not if I can; the presense of the MyAssembly.CustomerA.dll should be enough.

Now, this question is similar: Using StructureMap, when a default concrete type is defined in one registry, can it be redefined in another registry?

But I don't want to leave it to "whatever StructureMap finds last."

Can this be done?


Profiles are kind of confusing, I don't believe they would work well for the this situation. It sounds like you want a method that says "use this a the default unless any other concrete type is registered."

I'm not aware of a way to do this, but you can make sure that your override types are registered last. I would have to see your configuration to give an exact picture, but the idea would be to call Initialize and set up everything except your customer specific stuff. Then call Configure and scan for additional assemblies. That way all your base types will be default unless you have added another implementation for that interface in a separate assembly.


Register the default instance before you scan for registries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜