using System.Collections.Generic;
namespace StructureMap4Test
private static void Main(string[] args)
var container = new Container(
config.For<IA>().Use<A>();
config.For<IB>().Use<B>();
config.For<IC>().Use<C>().AlwaysUnique();
config.For<IList<ICPlugIn>>().Use(c => c.GetAllInstances<ICPlugIn>().ToList()).AlwaysUnique();
config.For<ICPlugIn>().Use<CPlugIn1>().AlwaysUnique();
config.For<ICPlugIn>().Use<CPlugIn2>().AlwaysUnique();
config.For<ICPlugIn>().Use<CPlugIn3>().AlwaysUnique();
var a = container.GetInstance<IA>();
Console.WriteLine(a.ToString());
var containerB = new Container(
config.For<IA>().Use<A>();
config.For<IB>().Use<B>();
config.For<IC>().Use<C>().AlwaysUnique();
scan.AssemblyContainingType<ICPlugIn>();
scan.WithDefaultConventions().OnAddedPluginTypes(c => c.ContainerScoped());
scan.AddAllTypesOf<ICPlugIn>();
var b = containerB.GetInstance<IA>();
Console.WriteLine(b.ToString());
public override string ToString()
var message = $"A: {GetHashCode()}";
message += Environment.NewLine + B;
message += Environment.NewLine + C;
public override string ToString()
var message = $"B: {GetHashCode()}";
message += Environment.NewLine + " " + C;
public interface ICPlugIn
public class CPlugIn1 : ICPlugIn
public class CPlugIn2 : ICPlugIn
public class CPlugIn3 : ICPlugIn
public C(IList<ICPlugIn> plugIns)
public IList<ICPlugIn> PlugIns { get; }
public override string ToString()
var message = $"C: {GetHashCode()}";
message += Environment.NewLine + " C.PlugIns:";
return PlugIns.Aggregate(message, (msg, p) => msg += Environment.NewLine + ($" {p} {p.GetHashCode()}"), accu=>accu);