CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Structurmap: Best attempt at getting all implementors of an interface from a profile

147 Views
Copy Code Show/Hide Line Numbers
[Xunit.Extensions.ContextSpecification.Concern("Exploratory")]
 public class StructuremapProfiles
 {
     Container _container;
     public StructuremapProfiles()
     {
         _container = new StructureMap.Container();
         _container.Configure(x =>
         {
             x.Profile("C", y =>
             {
                 y.For<Implementor1>().Use<Implementor1>().Named("C1");
                 y.For<Implementor2>().Use<Implementor2>().Named("C2");
                 y.For<IEnumerable<IMyInterface>>().Use(ctx => new IMyInterface[]{
                           ctx.GetInstance<Implementor1>("C1"),
                           ctx.GetInstance<Implementor2>("C2"),
                       });
             });
             x.For<DependsOnManyIMyInterfaces>();
         });
     }
     [Fact]
     public void get_enumeration_from_within_profile()
     {
         _container.SetDefaultsToProfile("C");
         _container.GetInstance<DependsOnManyIMyInterfaces>().Interfaces.Count().ShouldBe(2);
     }
     class Implementor1 : IMyInterface { }
     class Implementor2 : IMyInterface { }
     interface IMyInterface { }
     class DependsOnManyIMyInterfaces
     {
         public IEnumerable<IMyInterface> Interfaces;
         public DependsOnManyIMyInterfaces(IEnumerable<IMyInterface> interfaces) { Interfaces = interfaces; }
     }
 
 }
by togakangaroo
  November 11, 2010 @ 6:45am
Tags:
Description:
http://groups.google.com/group/structuremap-users/browse_thread/thread/df86b36fc049559

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate