I have an interface IFileSystemStructureEvaluator with two concrete implementations: NtfsFileSystemStructureEvaluator and FtpFileSystemStructureEvaluator.
I want to be able to request the appropriate IFileSystemStructureEvaluator depending on whether the Uri that is passed to the constructor is a file uri of an FTP uri.
How can I achieve this in StructureMap?
Thanks
You should check out the Conditional Object construction post by Jeremy Miller. It allows you to use some conditional checks in determining what you'll get as an instance. It sounds like a solution to your problem.
http://codebetter.com/blogs/jeremy.miller/archive/2009/01/18/conditional-object-construction-in-structuremap-i-e-fun-with-lambdas.aspx
Edits below
There have been several questions on the StructureMap users list about doing conditional construction (i.e., return this object if this condition, else this other object). In order to meet this apparent need, StructureMap 2.5.2 introduces the new ConditionalInstance that allows a user to effectively switch the active Instance based on a Predicate boolean test. Here's a quick example of using the new Conditional() syntax of InstanceExpression:
var container = new Container(x =>
{
x.InstanceOf<Rule>().Is.Conditional(o =>
{
o.If(c => false).ThenIt.Is.OfConcreteType<ARule>();
o.If(c => true).ThenIt.IsThis(GREEN);
o.TheDefault.IsThis(RED);
}).WithName("conditional");
});
More available at the wayback machine https://web.archive.org/web/20090506031557/http://codebetter.com/blogs/jeremy.miller/archive/2009/01/18/conditional-object-construction-in-structuremap-i-e-fun-with-lambdas.aspx
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