public async Task BuildCatalog(IEnumerable <string> solutions, IStructureMapWiringReporter reporter, Dictionary <string, string> solutionProperties = null) { if (solutions == null) { throw new ArgumentNullException(nameof(solutions)); } if (reporter == null) { throw new ArgumentNullException(nameof(reporter)); } var solutionsToAnalyze = solutions as string[] ?? solutions.ToArray(); if (!solutionsToAnalyze.Any()) { return; } var collector = new StructureMapWiringAnalyzer(); await Task.WhenAll(solutionsToAnalyze.Select(x => AnalyzeSolution(x, collector, solutionProperties)).ToArray()) .ConfigureAwait(false); var wirings = collector.GetWirings(); reporter.WriteWirings(wirings); }
public async void CanDetermineWirings() { var analyzer = new StructureMapWiringAnalyzer(); await TestHelper.GetDiagnosticsAsync(analyzer, @"using System; using System.Threading; using System.Threading.Tasks; using StructureMap; using StructureMap.Pipeline; class TestClass { void TestMethod() { new Container(c => { If plugin = null; var k = new K(); c.For<If>().Singleton().Use<T>(); c.For<If>().LifecycleIs(new SingletonLifecycle()).Use<T>(); c.For<If>().LifecycleIs<SingletonLifecycle>().Use<T>(); c.For(typeof(If)).LifecycleIs(new SingletonLifecycle()).Use(typeof(T)); c.ForSingletonOf(typeof(If)).Use(typeof(T)); c.ForSingletonOf<If>().Use<T>(); c.For<If>().LifecycleIs<SingletonLifecycle>().Use(new T()); c.For<If>().LifecycleIs<SingletonLifecycle>().Use(() => new T()); c.For<If>(new SingletonLifecycle()).Use<T>(); c.For(typeof(If), new SingletonLifecycle()).Use(typeof(T)); c.For(plugin.GetType()).LifecycleIs(new SingletonLifecycle()).Use(typeof(T)); c.ForSingletonOf(typeof(If)).Use(ctx => new K()); c.For<If>().LifecycleIs<SingletonLifecycle>().Use(() => new T()); c.ForSingletonOf(typeof(If)).Use(""desc"", ctx => k); c.ForSingletonOf(typeof(If)).Use(typeof(T)); c.For(typeof(If)).Singleton().Use(k); c.For<If>().AlwaysUnique().Use<T>(); c.For<If>().LifecycleIs(new UniquePerRequestLifecycle()).Use<T>(); c.For<If>().Transient().Use<T>(); c.For<If>().Transient().Add(new T()); c.For<If>().Transient().Add<T>(); c.For<If>().Use<T>(); c.For<If>().Add<T>(); }); } interface If { } class T : If { } class K : T { } class N<M> { } }"); var wirings = analyzer.GetWirings(); var grouped = wirings.GroupBy(x => x.Lifecycle).ToDictionary(x => x.Key, x => x.ToArray()); Assert.Equal(16, grouped[StructureMapLifecycle.Singleton].Length); Assert.Equal(2, grouped[StructureMapLifecycle.Unique].Length); Assert.Equal(3, grouped[StructureMapLifecycle.Transient].Length); Assert.Equal(2, grouped[StructureMapLifecycle.TransientImplicit].Length); }