Created
September 29, 2011 17:36
-
-
Save andreasohlund/1251362 to your computer and use it in GitHub Desktop.
StructureMapBug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace NamedInstancesBug | |
| { | |
| using NUnit.Framework; | |
| using StructureMap; | |
| [TestFixture] | |
| public class When_missing_named_instance_handler_is_invoked | |
| { | |
| [Test] | |
| public void Should_pass_the_name_of_the_named_instance_to_the_context() | |
| { | |
| var container = new Container(x=> | |
| { | |
| x.For<ISomeThing>().MissingNamedInstanceIs.ConstructedBy(ctx => | |
| { | |
| return new SomeThing(ctx.RequestedName); | |
| }); | |
| x.ForConcreteType<ClassDependingOnISomething>() | |
| .Configure.Ctor<ISomeThing>().Named("SomeThing"); | |
| }); | |
| var something = container.GetInstance<ISomeThing>("SomeName"); | |
| var other = container.GetInstance<ClassDependingOnISomething>(); | |
| Assert.AreEqual("SomeName",((SomeThing)something).Name); | |
| Assert.AreEqual("SomeThing", other.NameOfSomething); | |
| } | |
| } | |
| public class ClassDependingOnISomething | |
| { | |
| ISomeThing someThing; | |
| public ClassDependingOnISomething(ISomeThing someThing) | |
| { | |
| this.someThing = someThing; | |
| } | |
| public string NameOfSomething | |
| { | |
| get { return ((SomeThing) someThing).Name; } | |
| } | |
| } | |
| public class SomeThing : ISomeThing | |
| { | |
| public string Name { get; set; } | |
| public SomeThing(string requestedName) | |
| { | |
| Name = requestedName; | |
| } | |
| } | |
| public interface ISomeThing | |
| { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same problem here - I have lots of similar registrations in the registries and I wanted to clean in up with similar implementation. RequestedName is always passed as "DEFAULT", so no cigar:(