diff --git a/readme/async-disposable-scope.md b/readme/async-disposable-scope.md index 4e58cbda6..d96a7b3fc 100644 --- a/readme/async-disposable-scope.md +++ b/readme/async-disposable-scope.md @@ -139,8 +139,8 @@ partial class Composition: IDisposable, IAsyncDisposable Func perBlockFunc1 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { Composition transientComposition3 = this; - Session localValue89 = new Session(transientComposition3); - return localValue89; + Session localValue93 = new Session(transientComposition3); + return localValue93; }); return new Program(perBlockFunc1); } diff --git a/readme/async-root.md b/readme/async-root.md index 6f564c66a..4ea629c57 100644 --- a/readme/async-root.md +++ b/readme/async-root.md @@ -51,26 +51,26 @@ partial class Composition public Task GetMyServiceAsync(CancellationToken cancellationToken) { TaskFactory perBlockTaskFactory2; - CancellationToken localCancellationToken39 = cancellationToken; + CancellationToken localCancellationToken43 = cancellationToken; TaskCreationOptions transientTaskCreationOptions3 = TaskCreationOptions.None; - TaskCreationOptions localTaskCreationOptions40 = transientTaskCreationOptions3; + TaskCreationOptions localTaskCreationOptions44 = transientTaskCreationOptions3; TaskContinuationOptions transientTaskContinuationOptions4 = TaskContinuationOptions.None; - TaskContinuationOptions localTaskContinuationOptions41 = transientTaskContinuationOptions4; + TaskContinuationOptions localTaskContinuationOptions45 = transientTaskContinuationOptions4; TaskScheduler transientTaskScheduler5 = TaskScheduler.Default; - TaskScheduler localTaskScheduler42 = transientTaskScheduler5; - perBlockTaskFactory2 = new TaskFactory(localCancellationToken39, localTaskCreationOptions40, localTaskContinuationOptions41, localTaskScheduler42); + TaskScheduler localTaskScheduler46 = transientTaskScheduler5; + perBlockTaskFactory2 = new TaskFactory(localCancellationToken43, localTaskCreationOptions44, localTaskContinuationOptions45, localTaskScheduler46); Func perBlockFunc1 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - IService localValue43 = new Service(new Dependency()); - return localValue43; + IService localValue47 = new Service(new Dependency()); + return localValue47; }); Task transientTask0; // Injects an instance factory - Func localFactory44 = perBlockFunc1; + Func localFactory48 = perBlockFunc1; // Injects a task factory creating and scheduling task objects - TaskFactory localTaskFactory45 = perBlockTaskFactory2; + TaskFactory localTaskFactory49 = perBlockTaskFactory2; // Creates and starts a task using the instance factory - transientTask0 = localTaskFactory45.StartNew(localFactory44); + transientTask0 = localTaskFactory49.StartNew(localFactory48); return transientTask0; } } diff --git a/readme/auto-scoped.md b/readme/auto-scoped.md index c754ff1b6..b87dfac3a 100644 --- a/readme/auto-scoped.md +++ b/readme/auto-scoped.md @@ -96,13 +96,13 @@ partial class Composition { Composition transientComposition3 = this; IService transientIService2; - Composition localBaseComposition91 = transientComposition3; + Composition localBaseComposition95 = transientComposition3; // Creates a session - var localSession92= new Composition(localBaseComposition91); + var localSession96= new Composition(localBaseComposition95); // Provides a root - transientIService2 = localSession92.SessionRoot; - IService localValue90 = transientIService2; - return localValue90; + transientIService2 = localSession96.SessionRoot; + IService localValue94 = transientIService2; + return localValue94; }); return new Program(perBlockFunc1); } diff --git a/readme/bind-attribute-for-a-generic-type.md b/readme/bind-attribute-for-a-generic-type.md index 0a64cb699..e1ee369a2 100644 --- a/readme/bind-attribute-for-a-generic-type.md +++ b/readme/bind-attribute-for-a-generic-type.md @@ -84,8 +84,8 @@ partial class Composition } IDependency transientIDependency1; - Facade localInstance_1182D12746 = _root._singletonFacade43!; - transientIDependency1 = localInstance_1182D12746.GetDependency(); + Facade localInstance_1182D12750 = _root._singletonFacade43!; + transientIDependency1 = localInstance_1182D12750.GetDependency(); return new Service(transientIDependency1); } } diff --git a/readme/bind-attribute-with-lifetime-and-tag.md b/readme/bind-attribute-with-lifetime-and-tag.md index 72d478a82..dd4f8a3af 100644 --- a/readme/bind-attribute-with-lifetime-and-tag.md +++ b/readme/bind-attribute-with-lifetime-and-tag.md @@ -84,8 +84,8 @@ partial class Composition _root._singletonFacade43 = new Facade(); } - Facade localInstance_1182D12748 = _root._singletonFacade43!; - _root._singletonIDependency0 = localInstance_1182D12748.Dependency; + Facade localInstance_1182D12752 = _root._singletonFacade43!; + _root._singletonIDependency0 = localInstance_1182D12752.Dependency; } } } diff --git a/readme/bind-attribute.md b/readme/bind-attribute.md index de3640945..daf213969 100644 --- a/readme/bind-attribute.md +++ b/readme/bind-attribute.md @@ -88,8 +88,8 @@ partial class Composition } IDependency transientIDependency1; - Facade localInstance_1182D12747 = _root._singletonFacade43!; - transientIDependency1 = localInstance_1182D12747.Dependency; + Facade localInstance_1182D12751 = _root._singletonFacade43!; + transientIDependency1 = localInstance_1182D12751.Dependency; return new Service(transientIDependency1); } } diff --git a/readme/build-up-of-an-existing-generic-object.md b/readme/build-up-of-an-existing-generic-object.md index 716c660f7..f666669e0 100644 --- a/readme/build-up-of-an-existing-generic-object.md +++ b/readme/build-up-of-an-existing-generic-object.md @@ -80,10 +80,10 @@ partial class Composition { Guid transientGuid2 = Guid.NewGuid(); Dependency transientDependency1; - Dependency localDependency52= new Dependency(); - localDependency52.SetId(transientGuid2); - localDependency52.Name = name; - transientDependency1 = localDependency52; + Dependency localDependency56= new Dependency(); + localDependency56.SetId(transientGuid2); + localDependency56.Name = name; + transientDependency1 = localDependency56; return new Service(transientDependency1); } } diff --git a/readme/build-up-of-an-existing-object.md b/readme/build-up-of-an-existing-object.md index 4d341319b..d37d7f80d 100644 --- a/readme/build-up-of-an-existing-object.md +++ b/readme/build-up-of-an-existing-object.md @@ -76,10 +76,10 @@ partial class Composition { Guid transientGuid2 = Guid.NewGuid(); Dependency transientDependency1; - var localDependency49= new Dependency(); - localDependency49.SetId(transientGuid2); - localDependency49.Name = name; - transientDependency1 = localDependency49; + var localDependency53= new Dependency(); + localDependency53.SetId(transientGuid2); + localDependency53.Name = name; + transientDependency1 = localDependency53; return new Service(transientDependency1); } } diff --git a/readme/di-tracing-via-serilog.md b/readme/di-tracing-via-serilog.md index f11f5190b..6e40986a1 100644 --- a/readme/di-tracing-via-serilog.md +++ b/readme/di-tracing-via-serilog.md @@ -39,7 +39,8 @@ partial class Composition .Bind().To(ctx => { ctx.Inject("from arg", out Serilog.ILogger logger); - return logger.ForContext(ctx.OwnerType); + var consumers = ctx.ConsumerTypes; + return consumers.Length == 1 ? logger.ForContext(consumers[0]) : logger; }) .Bind().To() @@ -92,8 +93,9 @@ partial class Composition get { Serilog.ILogger transientILogger0; - Serilog.ILogger localLogger1 = _argLogger; - transientILogger0 = localLogger1.ForContext(typeof(Serilog.ILogger)); + Serilog.ILogger localLogger2 = _argLogger; + var localConsumers3= new Type[1]{typeof(Composition)}; + transientILogger0 = localConsumers3.Length == 1 ? localLogger2.ForContext(localConsumers3[0]) : localLogger2; return transientILogger0; } } @@ -107,7 +109,8 @@ partial class Composition OnNewInstance(ref transientDependency2, null, Lifetime.Transient); Serilog.ILogger transientILogger1; Serilog.ILogger localLogger0 = _argLogger; - transientILogger1 = localLogger0.ForContext(typeof(Service)); + var localConsumers1= new Type[1]{typeof(Service)}; + transientILogger1 = localConsumers1.Length == 1 ? localLogger0.ForContext(localConsumers1[0]) : localLogger0; Service transientService0 = new Service(transientILogger1, OnDependencyInjection(transientDependency2, null, Lifetime.Transient)); OnNewInstance(ref transientService0, null, Lifetime.Transient); return OnDependencyInjection(transientService0, null, Lifetime.Transient); diff --git a/readme/exposed-generic-roots-with-args.md b/readme/exposed-generic-roots-with-args.md index 5969357ff..2ddbb6e90 100644 --- a/readme/exposed-generic-roots-with-args.md +++ b/readme/exposed-generic-roots-with-args.md @@ -73,9 +73,9 @@ partial class Composition } Integration.IMyGenericService transientIMyGenericService1; - int localId3 = id; - Integration.CompositionWithGenericRootsAndArgsInOtherProject localInstance_1182D1274 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject44!; - transientIMyGenericService1 = localInstance_1182D1274.GetMyService(localId3); + int localId5 = id; + Integration.CompositionWithGenericRootsAndArgsInOtherProject localInstance_1182D1276 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject44!; + transientIMyGenericService1 = localInstance_1182D1276.GetMyService(localId5); return new Program(transientIMyGenericService1); } } diff --git a/readme/exposed-generic-roots.md b/readme/exposed-generic-roots.md index 6ebe88a2b..313ba8bde 100644 --- a/readme/exposed-generic-roots.md +++ b/readme/exposed-generic-roots.md @@ -76,8 +76,8 @@ partial class Composition } Integration.IMyGenericService transientIMyGenericService1; - Integration.CompositionWithGenericRootsInOtherProject localInstance_1182D1272 = _root._singletonCompositionWithGenericRootsInOtherProject43!; - transientIMyGenericService1 = localInstance_1182D1272.GetMyService(); + Integration.CompositionWithGenericRootsInOtherProject localInstance_1182D1274 = _root._singletonCompositionWithGenericRootsInOtherProject43!; + transientIMyGenericService1 = localInstance_1182D1274.GetMyService(); return new Program(transientIMyGenericService1); } } diff --git a/readme/exposed-roots-via-arg.md b/readme/exposed-roots-via-arg.md index abfc99c40..4705f0940 100644 --- a/readme/exposed-roots-via-arg.md +++ b/readme/exposed-roots-via-arg.md @@ -60,8 +60,8 @@ partial class Composition get { Integration.IMyService transientIMyService1; - Integration.CompositionInOtherProject localInstance_1182D1276 = _argBaseComposition; - transientIMyService1 = localInstance_1182D1276.MyService; + Integration.CompositionInOtherProject localInstance_1182D1278 = _argBaseComposition; + transientIMyService1 = localInstance_1182D1278.MyService; return new Program(transientIMyService1); } } diff --git a/readme/exposed-roots-via-root-arg.md b/readme/exposed-roots-via-root-arg.md index da9e17dee..6f4c4a049 100644 --- a/readme/exposed-roots-via-root-arg.md +++ b/readme/exposed-roots-via-root-arg.md @@ -55,8 +55,8 @@ partial class Composition public Program GetProgram(Integration.CompositionInOtherProject baseComposition) { Integration.IMyService transientIMyService1; - Integration.CompositionInOtherProject localInstance_1182D1277 = baseComposition; - transientIMyService1 = localInstance_1182D1277.MyService; + Integration.CompositionInOtherProject localInstance_1182D1279 = baseComposition; + transientIMyService1 = localInstance_1182D1279.MyService; return new Program(transientIMyService1); } } diff --git a/readme/exposed-roots-with-tags.md b/readme/exposed-roots-with-tags.md index 91a941ee5..23bf959bf 100644 --- a/readme/exposed-roots-with-tags.md +++ b/readme/exposed-roots-with-tags.md @@ -71,8 +71,8 @@ partial class Composition } Integration.IMyService transientIMyService1; - Integration.CompositionWithTagsInOtherProject localInstance_1182D1278 = _root._singletonCompositionWithTagsInOtherProject43!; - transientIMyService1 = localInstance_1182D1278.MyService; + Integration.CompositionWithTagsInOtherProject localInstance_1182D12710 = _root._singletonCompositionWithTagsInOtherProject43!; + transientIMyService1 = localInstance_1182D12710.MyService; return new Program(transientIMyService1); } } diff --git a/readme/exposed-roots.md b/readme/exposed-roots.md index a08ab849b..8cf2742b3 100644 --- a/readme/exposed-roots.md +++ b/readme/exposed-roots.md @@ -74,8 +74,8 @@ partial class Composition } Integration.IMyService transientIMyService1; - Integration.CompositionInOtherProject localInstance_1182D1275 = _root._singletonCompositionInOtherProject43!; - transientIMyService1 = localInstance_1182D1275.MyService; + Integration.CompositionInOtherProject localInstance_1182D1277 = _root._singletonCompositionInOtherProject43!; + transientIMyService1 = localInstance_1182D1277.MyService; return new Program(transientIMyService1); } } diff --git a/readme/factory.md b/readme/factory.md index 7eccbaeb4..b1b06972b 100644 --- a/readme/factory.md +++ b/readme/factory.md @@ -110,15 +110,15 @@ partial class Composition // Some custom logic for creating an instance. // For example, here's how you can inject and initialize // an instance of a particular type: - bool localIsFake50 = isFake; - if (localIsFake50) + bool localIsFake54 = isFake; + if (localIsFake54) { {transientIDependency1 = new FakeDependency(); goto transientIDependency1Finish; } } - Dependency localDependency51 = new Dependency(transientDateTimeOffset3); - localDependency51.Initialize(); - transientIDependency1 = localDependency51; + Dependency localDependency55 = new Dependency(transientDateTimeOffset3); + localDependency55.Initialize(); + transientIDependency1 = localDependency55; transientIDependency1Finish:; return new Service(transientIDependency1); } diff --git a/readme/func-with-arguments.md b/readme/func-with-arguments.md index 1359860b4..b8f93c704 100644 --- a/readme/func-with-arguments.md +++ b/readme/func-with-arguments.md @@ -128,8 +128,8 @@ partial class Composition } } - Dependency localDependency56 = new Dependency(_root._singletonClock43!, transientInt323, transientInt324); - return localDependency56; + Dependency localDependency60 = new Dependency(_root._singletonClock43!, transientInt323, transientInt324); + return localDependency60; }; return new Service(transientFunc1); } diff --git a/readme/func-with-tag.md b/readme/func-with-tag.md index 291d269e8..fb91dd12f 100644 --- a/readme/func-with-tag.md +++ b/readme/func-with-tag.md @@ -60,8 +60,8 @@ partial class Composition { Func perBlockFunc1 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - IDependency localValue57 = new Dependency(); - return localValue57; + IDependency localValue61 = new Dependency(); + return localValue61; }); return new Service(perBlockFunc1); } diff --git a/readme/func.md b/readme/func.md index 4a1ee47f0..b38dbe65b 100644 --- a/readme/func.md +++ b/readme/func.md @@ -64,8 +64,8 @@ partial class Composition { Func perBlockFunc1 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - IDependency localValue55 = new Dependency(); - return localValue55; + IDependency localValue59 = new Dependency(); + return localValue59; }); return new Service(perBlockFunc1); } diff --git a/readme/generic-async-composition-roots-with-constraints.md b/readme/generic-async-composition-roots-with-constraints.md index edc9978da..78a476c90 100644 --- a/readme/generic-async-composition-roots-with-constraints.md +++ b/readme/generic-async-composition-roots-with-constraints.md @@ -85,29 +85,29 @@ partial class Composition where T2: IDisposable { TaskFactory> perBlockTaskFactory2; - CancellationToken localCancellationToken71 = cancellationToken; + CancellationToken localCancellationToken75 = cancellationToken; TaskCreationOptions transientTaskCreationOptions3 = TaskCreationOptions.None; - TaskCreationOptions localTaskCreationOptions72 = transientTaskCreationOptions3; + TaskCreationOptions localTaskCreationOptions76 = transientTaskCreationOptions3; TaskContinuationOptions transientTaskContinuationOptions4 = TaskContinuationOptions.None; - TaskContinuationOptions localTaskContinuationOptions73 = transientTaskContinuationOptions4; + TaskContinuationOptions localTaskContinuationOptions77 = transientTaskContinuationOptions4; TaskScheduler transientTaskScheduler5 = TaskScheduler.Default; - TaskScheduler localTaskScheduler74 = transientTaskScheduler5; - perBlockTaskFactory2 = new TaskFactory>(localCancellationToken71, localTaskCreationOptions72, localTaskContinuationOptions73, localTaskScheduler74); + TaskScheduler localTaskScheduler78 = transientTaskScheduler5; + perBlockTaskFactory2 = new TaskFactory>(localCancellationToken75, localTaskCreationOptions76, localTaskContinuationOptions77, localTaskScheduler78); Func> perBlockFunc1 = new Func>([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { OtherService transientOtherService6; - IDependency localDependency76 = new Dependency(); - transientOtherService6 = new OtherService(localDependency76); - IService localValue75 = transientOtherService6; - return localValue75; + IDependency localDependency80 = new Dependency(); + transientOtherService6 = new OtherService(localDependency80); + IService localValue79 = transientOtherService6; + return localValue79; }); Task> transientTask0; // Injects an instance factory - Func> localFactory77 = perBlockFunc1; + Func> localFactory81 = perBlockFunc1; // Injects a task factory creating and scheduling task objects - TaskFactory> localTaskFactory78 = perBlockTaskFactory2; + TaskFactory> localTaskFactory82 = perBlockTaskFactory2; // Creates and starts a task using the instance factory - transientTask0 = localTaskFactory78.StartNew(localFactory77); + transientTask0 = localTaskFactory82.StartNew(localFactory81); return transientTask0; } @@ -117,26 +117,26 @@ partial class Composition where T: struct { TaskFactory> perBlockTaskFactory2; - CancellationToken localCancellationToken79 = cancellationToken; + CancellationToken localCancellationToken83 = cancellationToken; TaskCreationOptions transientTaskCreationOptions3 = TaskCreationOptions.None; - TaskCreationOptions localTaskCreationOptions80 = transientTaskCreationOptions3; + TaskCreationOptions localTaskCreationOptions84 = transientTaskCreationOptions3; TaskContinuationOptions transientTaskContinuationOptions4 = TaskContinuationOptions.None; - TaskContinuationOptions localTaskContinuationOptions81 = transientTaskContinuationOptions4; + TaskContinuationOptions localTaskContinuationOptions85 = transientTaskContinuationOptions4; TaskScheduler transientTaskScheduler5 = TaskScheduler.Default; - TaskScheduler localTaskScheduler82 = transientTaskScheduler5; - perBlockTaskFactory2 = new TaskFactory>(localCancellationToken79, localTaskCreationOptions80, localTaskContinuationOptions81, localTaskScheduler82); + TaskScheduler localTaskScheduler86 = transientTaskScheduler5; + perBlockTaskFactory2 = new TaskFactory>(localCancellationToken83, localTaskCreationOptions84, localTaskContinuationOptions85, localTaskScheduler86); Func> perBlockFunc1 = new Func>([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - IService localValue83 = new Service(new Dependency()); - return localValue83; + IService localValue87 = new Service(new Dependency()); + return localValue87; }); Task> transientTask0; // Injects an instance factory - Func> localFactory84 = perBlockFunc1; + Func> localFactory88 = perBlockFunc1; // Injects a task factory creating and scheduling task objects - TaskFactory> localTaskFactory85 = perBlockTaskFactory2; + TaskFactory> localTaskFactory89 = perBlockTaskFactory2; // Creates and starts a task using the instance factory - transientTask0 = localTaskFactory85.StartNew(localFactory84); + transientTask0 = localTaskFactory89.StartNew(localFactory88); return transientTask0; } } diff --git a/readme/generic-composition-roots-with-constraints.md b/readme/generic-composition-roots-with-constraints.md index 25ff096e2..b9729db26 100644 --- a/readme/generic-composition-roots-with-constraints.md +++ b/readme/generic-composition-roots-with-constraints.md @@ -83,8 +83,8 @@ partial class Composition where T2: IDisposable { OtherService transientOtherService0; - IDependency localDependency86 = new Dependency(); - transientOtherService0 = new OtherService(localDependency86); + IDependency localDependency90 = new Dependency(); + transientOtherService0 = new OtherService(localDependency90); return transientOtherService0; } diff --git a/readme/generic-composition-roots.md b/readme/generic-composition-roots.md index 30d38f321..71aa503c0 100644 --- a/readme/generic-composition-roots.md +++ b/readme/generic-composition-roots.md @@ -76,8 +76,8 @@ partial class Composition public IService GetOtherService() { OtherService transientOtherService0; - IDependency localDependency87 = new Dependency(); - transientOtherService0 = new OtherService(localDependency87); + IDependency localDependency91 = new Dependency(); + transientOtherService0 = new OtherService(localDependency91); return transientOtherService0; } diff --git a/readme/lazy.md b/readme/lazy.md index 8096d4a1c..98908cc83 100644 --- a/readme/lazy.md +++ b/readme/lazy.md @@ -55,14 +55,14 @@ partial class Composition { Func perBlockFunc2 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - IDependency localValue58 = new Dependency(); - return localValue58; + IDependency localValue62 = new Dependency(); + return localValue62; }); Lazy transientLazy1; // Injects an instance factory - Func localFactory59 = perBlockFunc2; + Func localFactory63 = perBlockFunc2; // Creates an instance that supports lazy initialization - transientLazy1 = new Lazy(localFactory59, true); + transientLazy1 = new Lazy(localFactory63, true); return new Service(transientLazy1); } } diff --git a/readme/manually-started-tasks.md b/readme/manually-started-tasks.md index 07b86e7da..c97a57df4 100644 --- a/readme/manually-started-tasks.md +++ b/readme/manually-started-tasks.md @@ -93,13 +93,13 @@ partial class Composition { Func perBlockFunc2 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - IDependency localValue60 = new Dependency(); - return localValue60; + IDependency localValue64 = new Dependency(); + return localValue64; }); Task transientTask1; - Func localFactory61 = perBlockFunc2; - CancellationToken localCancellationToken62 = cancellationToken; - transientTask1 = new Task(localFactory61, localCancellationToken62); + Func localFactory65 = perBlockFunc2; + CancellationToken localCancellationToken66 = cancellationToken; + transientTask1 = new Task(localFactory65, localCancellationToken66); return new Service(transientTask1); } } diff --git a/readme/scope.md b/readme/scope.md index 34cdd7499..e8126a9f3 100644 --- a/readme/scope.md +++ b/readme/scope.md @@ -137,8 +137,8 @@ partial class Composition: IDisposable Func perBlockFunc1 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { Composition transientComposition3 = this; - Session localValue93 = new Session(transientComposition3); - return localValue93; + Session localValue97 = new Session(transientComposition3); + return localValue97; }); return new Program(perBlockFunc1); } diff --git a/readme/serilog.md b/readme/serilog.md index 5f748b72b..ea73525f1 100644 --- a/readme/serilog.md +++ b/readme/serilog.md @@ -41,7 +41,8 @@ partial class Composition .Bind().To(ctx => { ctx.Inject("from arg", out var logger); - return logger.ForContext(ctx.OwnerType); + var consumers = ctx.ConsumerTypes; + return consumers.Length == 1 ? logger.ForContext(consumers[0]) : logger; }) .Bind().To() @@ -82,11 +83,13 @@ partial class Composition get { Serilog.ILogger transientILogger3; - Serilog.ILogger localLogger9 = _argLogger; - transientILogger3 = localLogger9.ForContext(typeof(Dependency)); + Serilog.ILogger localLogger11 = _argLogger; + var localConsumers12= new Type[1]{typeof(Dependency)}; + transientILogger3 = localConsumers12.Length == 1 ? localLogger11.ForContext(localConsumers12[0]) : localLogger11; Serilog.ILogger transientILogger1; - Serilog.ILogger localLogger10 = _argLogger; - transientILogger1 = localLogger10.ForContext(typeof(Service)); + Serilog.ILogger localLogger13 = _argLogger; + var localConsumers14= new Type[1]{typeof(Service)}; + transientILogger1 = localConsumers14.Length == 1 ? localLogger13.ForContext(localConsumers14[0]) : localLogger13; return new Service(transientILogger1, new Dependency(transientILogger3)); } } diff --git a/readme/simplified-factory.md b/readme/simplified-factory.md index 1c909e10f..4f77dbf8b 100644 --- a/readme/simplified-factory.md +++ b/readme/simplified-factory.md @@ -82,11 +82,11 @@ partial class Composition get { Dependency transientDependency1; - Dependency localDependency53 = new Dependency(); + Dependency localDependency57 = new Dependency(); DateTimeOffset transientDateTimeOffset3 = DateTimeOffset.Now; - DateTimeOffset localTime54 = transientDateTimeOffset3; - localDependency53.Initialize(localTime54); - transientDependency1 = localDependency53; + DateTimeOffset localTime58 = transientDateTimeOffset3; + localDependency57.Initialize(localTime58); + transientDependency1 = localDependency57; return new Service(transientDependency1); } } diff --git a/readme/task.md b/readme/task.md index cf44e16c2..26c314b8d 100644 --- a/readme/task.md +++ b/readme/task.md @@ -80,26 +80,26 @@ partial class Composition public IService GetRoot(CancellationToken cancellationToken) { TaskFactory perBlockTaskFactory3; - CancellationToken localCancellationToken63 = cancellationToken; + CancellationToken localCancellationToken67 = cancellationToken; TaskCreationOptions transientTaskCreationOptions4 = TaskCreationOptions.None; - TaskCreationOptions localTaskCreationOptions64 = transientTaskCreationOptions4; + TaskCreationOptions localTaskCreationOptions68 = transientTaskCreationOptions4; TaskContinuationOptions transientTaskContinuationOptions5 = TaskContinuationOptions.None; - TaskContinuationOptions localTaskContinuationOptions65 = transientTaskContinuationOptions5; + TaskContinuationOptions localTaskContinuationOptions69 = transientTaskContinuationOptions5; TaskScheduler transientTaskScheduler6 = TaskScheduler.Current; - TaskScheduler localTaskScheduler66 = transientTaskScheduler6; - perBlockTaskFactory3 = new TaskFactory(localCancellationToken63, localTaskCreationOptions64, localTaskContinuationOptions65, localTaskScheduler66); + TaskScheduler localTaskScheduler70 = transientTaskScheduler6; + perBlockTaskFactory3 = new TaskFactory(localCancellationToken67, localTaskCreationOptions68, localTaskContinuationOptions69, localTaskScheduler70); Func perBlockFunc2 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - IDependency localValue67 = new Dependency(); - return localValue67; + IDependency localValue71 = new Dependency(); + return localValue71; }); Task transientTask1; // Injects an instance factory - Func localFactory68 = perBlockFunc2; + Func localFactory72 = perBlockFunc2; // Injects a task factory creating and scheduling task objects - TaskFactory localTaskFactory69 = perBlockTaskFactory3; + TaskFactory localTaskFactory73 = perBlockTaskFactory3; // Creates and starts a task using the instance factory - transientTask1 = localTaskFactory69.StartNew(localFactory68); + transientTask1 = localTaskFactory73.StartNew(localFactory72); return new Service(transientTask1); } } diff --git a/readme/threadsafe-hint.md b/readme/threadsafe-hint.md index 854c3380e..c286c9961 100644 --- a/readme/threadsafe-hint.md +++ b/readme/threadsafe-hint.md @@ -58,8 +58,8 @@ partial class Composition { Func perBlockFunc0 = new Func([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { - IDependency localValue88 = new Dependency(); - return localValue88; + IDependency localValue92 = new Dependency(); + return localValue92; }); _root._singletonService44 = new Service(perBlockFunc0); } diff --git a/readme/tracking-async-disposable-instances-in-delegates.md b/readme/tracking-async-disposable-instances-in-delegates.md index d146eba97..12a9a3334 100644 --- a/readme/tracking-async-disposable-instances-in-delegates.md +++ b/readme/tracking-async-disposable-instances-in-delegates.md @@ -106,23 +106,23 @@ partial class Composition accumulator47.Add(transientDependency4); } Owned transientOwned3; - Owned localOwned12 = accumulator47; - transientOwned3 = localOwned12; + Owned localOwned16 = accumulator47; + transientOwned3 = localOwned16; using (_lock.EnterScope()) { accumulator47.Add(transientOwned3); } Owned perBlockOwned2; // Creates the owner of an instance - IOwned localOwned13 = transientOwned3; - IDependency localValue14 = transientDependency4; - perBlockOwned2 = new Owned(localValue14, localOwned13); + IOwned localOwned17 = transientOwned3; + IDependency localValue18 = transientDependency4; + perBlockOwned2 = new Owned(localValue18, localOwned17); using (_lock.EnterScope()) { accumulator47.Add(perBlockOwned2); } - Owned localValue11 = perBlockOwned2; - return localValue11; + Owned localValue15 = perBlockOwned2; + return localValue15; }); Service transientService0 = new Service(perBlockFunc1); using (_lock.EnterScope()) diff --git a/readme/tracking-async-disposable-instances-per-a-composition-root.md b/readme/tracking-async-disposable-instances-per-a-composition-root.md index 99b9511db..e302bfba3 100644 --- a/readme/tracking-async-disposable-instances-per-a-composition-root.md +++ b/readme/tracking-async-disposable-instances-per-a-composition-root.md @@ -98,15 +98,15 @@ partial class Composition Owned perBlockOwned0; // Creates the owner of an instance Owned transientOwned1; - Owned localOwned17 = accumulator46; - transientOwned1 = localOwned17; + Owned localOwned21 = accumulator46; + transientOwned1 = localOwned21; using (_lock.EnterScope()) { accumulator46.Add(transientOwned1); } - IOwned localOwned15 = transientOwned1; - IService localValue16 = new Service(transientDependency3); - perBlockOwned0 = new Owned(localValue16, localOwned15); + IOwned localOwned19 = transientOwned1; + IService localValue20 = new Service(transientDependency3); + perBlockOwned0 = new Owned(localValue20, localOwned19); using (_lock.EnterScope()) { accumulator46.Add(perBlockOwned0); diff --git a/readme/tracking-disposable-instances-in-delegates.md b/readme/tracking-disposable-instances-in-delegates.md index 20df019b8..497496c17 100644 --- a/readme/tracking-disposable-instances-in-delegates.md +++ b/readme/tracking-disposable-instances-in-delegates.md @@ -99,23 +99,23 @@ partial class Composition accumulator47.Add(transientDependency4); } Owned transientOwned3; - Owned localOwned19 = accumulator47; - transientOwned3 = localOwned19; + Owned localOwned23 = accumulator47; + transientOwned3 = localOwned23; using (_lock.EnterScope()) { accumulator47.Add(transientOwned3); } Owned perBlockOwned2; // Creates the owner of an instance - IOwned localOwned20 = transientOwned3; - IDependency localValue21 = transientDependency4; - perBlockOwned2 = new Owned(localValue21, localOwned20); + IOwned localOwned24 = transientOwned3; + IDependency localValue25 = transientDependency4; + perBlockOwned2 = new Owned(localValue25, localOwned24); using (_lock.EnterScope()) { accumulator47.Add(perBlockOwned2); } - Owned localValue18 = perBlockOwned2; - return localValue18; + Owned localValue22 = perBlockOwned2; + return localValue22; }); Service transientService0 = new Service(perBlockFunc1); using (_lock.EnterScope()) diff --git a/readme/tracking-disposable-instances-per-a-composition-root.md b/readme/tracking-disposable-instances-per-a-composition-root.md index 34f36c6bf..a37c30f88 100644 --- a/readme/tracking-disposable-instances-per-a-composition-root.md +++ b/readme/tracking-disposable-instances-per-a-composition-root.md @@ -94,15 +94,15 @@ partial class Composition Owned perBlockOwned0; // Creates the owner of an instance Owned transientOwned1; - Owned localOwned24 = accumulator46; - transientOwned1 = localOwned24; + Owned localOwned28 = accumulator46; + transientOwned1 = localOwned28; using (_lock.EnterScope()) { accumulator46.Add(transientOwned1); } - IOwned localOwned22 = transientOwned1; - IService localValue23 = new Service(transientDependency3); - perBlockOwned0 = new Owned(localValue23, localOwned22); + IOwned localOwned26 = transientOwned1; + IService localValue27 = new Service(transientDependency3); + perBlockOwned0 = new Owned(localValue27, localOwned26); using (_lock.EnterScope()) { accumulator46.Add(perBlockOwned0); diff --git a/readme/tracking-disposable-instances-using-pre-built-classes.md b/readme/tracking-disposable-instances-using-pre-built-classes.md index 795e4246d..6c1df2c01 100644 --- a/readme/tracking-disposable-instances-using-pre-built-classes.md +++ b/readme/tracking-disposable-instances-using-pre-built-classes.md @@ -147,15 +147,15 @@ partial class Composition: IDisposable Abstractions.Own perBlockOwn3; // Creates the owner of an instance - Abstractions.Own localOwn26 = accumulator50; - IDependency localValue27 = _root._singletonDependency44!; - perBlockOwn3 = new Abstractions.Own(localValue27, localOwn26); + Abstractions.Own localOwn30 = accumulator50; + IDependency localValue31 = _root._singletonDependency44!; + perBlockOwn3 = new Abstractions.Own(localValue31, localOwn30); using (_lock.EnterScope()) { accumulator50.Add(perBlockOwn3); } - Abstractions.Own localValue25 = perBlockOwn3; - return localValue25; + Abstractions.Own localValue29 = perBlockOwn3; + return localValue29; }); Func> perBlockFunc1 = new Func>([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { @@ -167,15 +167,15 @@ partial class Composition: IDisposable } Abstractions.Own perBlockOwn5; // Creates the owner of an instance - Abstractions.Own localOwn29 = accumulator50; - IDependency localValue30 = transientDependency7; - perBlockOwn5 = new Abstractions.Own(localValue30, localOwn29); + Abstractions.Own localOwn33 = accumulator50; + IDependency localValue34 = transientDependency7; + perBlockOwn5 = new Abstractions.Own(localValue34, localOwn33); using (_lock.EnterScope()) { accumulator50.Add(perBlockOwn5); } - Abstractions.Own localValue28 = perBlockOwn5; - return localValue28; + Abstractions.Own localValue32 = perBlockOwn5; + return localValue32; }); Service transientService0 = new Service(perBlockFunc1, perBlockFunc2); using (_lock.EnterScope()) diff --git a/readme/tracking-disposable-instances-with-different-lifetimes.md b/readme/tracking-disposable-instances-with-different-lifetimes.md index 056db1ccf..dd465bbd1 100644 --- a/readme/tracking-disposable-instances-with-different-lifetimes.md +++ b/readme/tracking-disposable-instances-with-different-lifetimes.md @@ -136,23 +136,23 @@ partial class Composition: IDisposable } Owned transientOwned4; - Owned localOwned32 = accumulator50; - transientOwned4 = localOwned32; + Owned localOwned36 = accumulator50; + transientOwned4 = localOwned36; using (_lock.EnterScope()) { accumulator50.Add(transientOwned4); } Owned perBlockOwned3; // Creates the owner of an instance - IOwned localOwned33 = transientOwned4; - IDependency localValue34 = _root._singletonDependency44!; - perBlockOwned3 = new Owned(localValue34, localOwned33); + IOwned localOwned37 = transientOwned4; + IDependency localValue38 = _root._singletonDependency44!; + perBlockOwned3 = new Owned(localValue38, localOwned37); using (_lock.EnterScope()) { accumulator50.Add(perBlockOwned3); } - Owned localValue31 = perBlockOwned3; - return localValue31; + Owned localValue35 = perBlockOwned3; + return localValue35; }); Func> perBlockFunc1 = new Func>([MethodImpl(MethodImplOptions.AggressiveInlining)] () => { @@ -163,23 +163,23 @@ partial class Composition: IDisposable accumulator50.Add(transientDependency8); } Owned transientOwned7; - Owned localOwned36 = accumulator50; - transientOwned7 = localOwned36; + Owned localOwned40 = accumulator50; + transientOwned7 = localOwned40; using (_lock.EnterScope()) { accumulator50.Add(transientOwned7); } Owned perBlockOwned6; // Creates the owner of an instance - IOwned localOwned37 = transientOwned7; - IDependency localValue38 = transientDependency8; - perBlockOwned6 = new Owned(localValue38, localOwned37); + IOwned localOwned41 = transientOwned7; + IDependency localValue42 = transientDependency8; + perBlockOwned6 = new Owned(localValue42, localOwned41); using (_lock.EnterScope()) { accumulator50.Add(perBlockOwned6); } - Owned localValue35 = perBlockOwned6; - return localValue35; + Owned localValue39 = perBlockOwned6; + return localValue39; }); Service transientService0 = new Service(perBlockFunc1, perBlockFunc2); using (_lock.EnterScope()) diff --git a/readme/valuetask.md b/readme/valuetask.md index 8ce54a96f..7b0a5a7c2 100644 --- a/readme/valuetask.md +++ b/readme/valuetask.md @@ -64,9 +64,9 @@ partial class Composition get { ValueTask transientValueTask1; - IDependency localValue70 = new Dependency(); + IDependency localValue74 = new Dependency(); // Initializes a new instance of the ValueTask class using the supplied instance - transientValueTask1 = new ValueTask(localValue70); + transientValueTask1 = new ValueTask(localValue74); return new Service(transientValueTask1); } } diff --git a/src/Pure.DI.Core/Components/Api.g.cs b/src/Pure.DI.Core/Components/Api.g.cs index a217034fd..ce5cb0440 100644 --- a/src/Pure.DI.Core/Components/Api.g.cs +++ b/src/Pure.DI.Core/Components/Api.g.cs @@ -2433,14 +2433,10 @@ internal interface IContext object Tag { get; } /// - /// The owner type of the instance being created. Cannot be used outside of the binding setup. See also - ///
For the instance, this is the owner type. - ///
For instances of and , this is the composition type. - ///
For the instance, this is the type that generated the block. - ///
For a instance, it is the composition root type. + /// The types of consumers for which the instance is created. Cannot be used outside of the binding setup. See also ///
/// - Type OwnerType { get; } + Type[] ConsumerTypes { get; } /// /// Injects an instance of type T. Cannot be used outside of the binding setup. diff --git a/src/Pure.DI.Core/Core/Code/BuildContext.cs b/src/Pure.DI.Core/Core/Code/BuildContext.cs index 29bfa34f9..d8f0fb915 100644 --- a/src/Pure.DI.Core/Core/Code/BuildContext.cs +++ b/src/Pure.DI.Core/Core/Code/BuildContext.cs @@ -9,7 +9,6 @@ internal record BuildContext( LinesBuilder Code, LinesBuilder LocalFunctionsCode, object? ContextTag, - string OwnerTypeName, bool? LockIsRequired, ImmutableArray Accumulators, bool IsFactory = false); \ No newline at end of file diff --git a/src/Pure.DI.Core/Core/Code/CompositionBuilder.cs b/src/Pure.DI.Core/Core/Code/CompositionBuilder.cs index f4eecf0d0..b450825f2 100644 --- a/src/Pure.DI.Core/Core/Code/CompositionBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/CompositionBuilder.cs @@ -34,7 +34,6 @@ public CompositionCode Build(DependencyGraph graph) new LinesBuilder(), new LinesBuilder(), root.Injection.Tag != MdTag.ContextTag ? root.Injection.Tag : null, - graph.Source.Name.FullName, null, root.Node.Accumulators.ToImmutableArray()); diff --git a/src/Pure.DI.Core/Core/Code/FactoryRewriter.cs b/src/Pure.DI.Core/Core/Code/FactoryRewriter.cs index c7310d548..7a71e998f 100644 --- a/src/Pure.DI.Core/Core/Code/FactoryRewriter.cs +++ b/src/Pure.DI.Core/Core/Code/FactoryRewriter.cs @@ -253,8 +253,14 @@ private bool TryInitialize( case nameof(IContext.Tag): return SyntaxFactory.ParseExpression(variable.Injection.Tag.ValueToString()); - case nameof(IContext.OwnerType) when _ctx is {} ctx: - return SyntaxFactory.ParseExpression($"typeof({ctx.OwnerTypeName})"); + case nameof(IContext.ConsumerTypes): + var consumers = variable.Info.GetTargetNodes().Select(targetNode => $"typeof({targetNode.Type.ToDisplayString()})").ToList(); + if (consumers.Count == 0 && _ctx is not null) + { + consumers.Add($"typeof({_ctx.DependencyGraph.Source.Name.FullName})"); + } + + return SyntaxFactory.ParseExpression($"new {Names.SystemNamespace}Type[{consumers.Count}]{{{string.Join(", ", consumers)}}}"); } } diff --git a/src/Pure.DI.Core/Core/Code/StatementCodeBuilder.cs b/src/Pure.DI.Core/Core/Code/StatementCodeBuilder.cs index dd306bf32..36ef4618f 100644 --- a/src/Pure.DI.Core/Core/Code/StatementCodeBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/StatementCodeBuilder.cs @@ -17,16 +17,6 @@ public void Build(BuildContext ctx, in IStatement statement) ctx = ctx with { ContextTag = curVariable.Injection.Tag }; } - var ownerTypeName = curVariable.Node.Lifetime switch - { - Lifetime.Transient => curVariable.TargetNode.Type.ToDisplayString(), - Lifetime.PerResolve => statement.GetPath().Last().Current.Node.Type.ToDisplayString(), - Lifetime.PerBlock => statement.Current.ParentBlock.Current.Node.Type.ToDisplayString(), - _ => ctx.DependencyGraph.Source.Name.FullName - }; - - ctx = ctx with { OwnerTypeName = ownerTypeName }; - switch (statement) { case Variable variable: diff --git a/src/Pure.DI.Core/Core/Code/Variable.cs b/src/Pure.DI.Core/Core/Code/Variable.cs index c734f58af..e56b980ed 100644 --- a/src/Pure.DI.Core/Core/Code/Variable.cs +++ b/src/Pure.DI.Core/Core/Code/Variable.cs @@ -5,7 +5,6 @@ internal record Variable( IStatement? Parent, int PerLifetimeId, in DependencyNode Node, - in DependencyNode TargetNode, in Injection Injection, ICollection Args, VariableInfo Info, diff --git a/src/Pure.DI.Core/Core/Code/VariableInfo.cs b/src/Pure.DI.Core/Core/Code/VariableInfo.cs index c3be41079..db06dd805 100644 --- a/src/Pure.DI.Core/Core/Code/VariableInfo.cs +++ b/src/Pure.DI.Core/Core/Code/VariableInfo.cs @@ -5,12 +5,19 @@ internal class VariableInfo private readonly HashSet _perBlockRefCounts = []; private readonly HashSet _variableParentBlocks = []; private readonly HashSet _blockParentBlocks = []; + private readonly List _targetNodes = []; public bool HasLocalMethod; public int RefCount { get; private set; } = 1; public int PerBlockRefCount => _perBlockRefCounts.Count + 1; + public void AddTargetNode(DependencyNode targetNode) => + _targetNodes.Add(targetNode); + + public IEnumerable GetTargetNodes() => + _targetNodes.GroupBy(i => i.Binding.Id).Select(i => i.First()); + public void AddRef(Block parentBlock) { RefCount++; @@ -28,6 +35,7 @@ public void Reset() _perBlockRefCounts.Clear(); _variableParentBlocks.Clear(); _blockParentBlocks.Clear(); + _targetNodes.Clear(); RefCount = 1; HasLocalMethod = false; } diff --git a/src/Pure.DI.Core/Core/Code/VariablesBuilder.cs b/src/Pure.DI.Core/Core/Code/VariablesBuilder.cs index 597764751..1407b0d26 100644 --- a/src/Pure.DI.Core/Core/Code/VariablesBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/VariablesBuilder.cs @@ -25,7 +25,6 @@ public Block Build( map, blockMap, rootNode, - rootNode, rootInjection, ref transientId)); @@ -125,10 +124,11 @@ public Block Build( map, blockMap, depNode with { Accumulators = accumulators }, - variable.Node, depInjection, ref transientId, cycleVariable); + + depVariable.Info.AddTargetNode(variable.Node); var isBlock = depNode.Lifetime is not Lifetime.Transient and not Lifetime.PerBlock || nodeInfo.IsDelegate(variable.Node) @@ -197,7 +197,6 @@ private Variable GetVariable( IDictionary map, IDictionary<(MdBinding, object?, int), Variable> blockMap, DependencyNode node, - DependencyNode targetNode, in Injection injection, ref int transientId, Variable? cycleVariable = null) @@ -220,7 +219,7 @@ private Variable GetVariable( { case Lifetime.Transient: { - var transientVariable = new Variable(setup, parentBlock, transientId++, node, targetNode, injection, new List(), new VariableInfo(), nodeInfo.IsLazy(node), false); + var transientVariable = new Variable(setup, parentBlock, transientId++, node, injection, new List(), new VariableInfo(), nodeInfo.IsLazy(node), false); if (node.Construct?.Source.Kind == MdConstructKind.Accumulator) { transientVariable.VariableCode = GetAccumulatorName(transientVariable); @@ -242,7 +241,7 @@ private Variable GetVariable( }; } - blockVariable = new Variable(setup, parentBlock, transientId++, node, targetNode, injection, new List(), new VariableInfo(), nodeInfo.IsLazy(node), false); + blockVariable = new Variable(setup, parentBlock, transientId++, node, injection, new List(), new VariableInfo(), nodeInfo.IsLazy(node), false); blockMap.Add(perBlockKey, blockVariable); return blockVariable; } @@ -261,7 +260,7 @@ private Variable GetVariable( }; } - variable = new Variable(setup, parentBlock, node.Binding.Id, node, targetNode, injection, new List(), new VariableInfo(), nodeInfo.IsLazy(node), false); + variable = new Variable(setup, parentBlock, node.Binding.Id, node, injection, new List(), new VariableInfo(), nodeInfo.IsLazy(node), false); map.Add(key, variable); return variable; } diff --git a/tests/Pure.DI.IntegrationTests/FactoryTests.cs b/tests/Pure.DI.IntegrationTests/FactoryTests.cs index 41286e279..015c43963 100644 --- a/tests/Pure.DI.IntegrationTests/FactoryTests.cs +++ b/tests/Pure.DI.IntegrationTests/FactoryTests.cs @@ -755,12 +755,12 @@ public static void Main() } [Theory] - /*[InlineData(nameof(Lifetime.Transient), "Service")] - [InlineData(nameof(Lifetime.Singleton), "Composition")] - [InlineData(nameof(Lifetime.Scoped), "Composition")] - [InlineData(nameof(Lifetime.PerBlock), "Service")]*/ - [InlineData(nameof(Lifetime.PerResolve), "Service")] - public async Task ShouldSupportFactoryWhenUsingOwnerType(string lifetime, string owner) + [InlineData(nameof(Lifetime.Transient), "ServiceAbc", "Service")] + [InlineData(nameof(Lifetime.Singleton), "Service", "ServiceAbc")] + [InlineData(nameof(Lifetime.Scoped), "Service", "ServiceAbc")] + [InlineData(nameof(Lifetime.PerBlock), "Service", "ServiceAbc")] + [InlineData(nameof(Lifetime.PerResolve), "Service", "ServiceAbc")] + public async Task ShouldSupportFactoryWhenUsingConsumers(string lifetime, params string[] consumers) { // Given @@ -777,9 +777,12 @@ interface IDependency class Dependency: IDependency { - public Dependency(string owner) + public Dependency(Type[] consumers) { - Console.WriteLine(owner); + foreach(var type in consumers) + { + Console.WriteLine(type.Name); + } } } @@ -790,14 +793,23 @@ interface IService class Service: IService { - public Service(IDependency dep) + public Service(IDependency dep, [Tag("Abc")] IService serviceAbc) { Dep = dep; - Console.WriteLine("Created"); } public IDependency Dep { get; } } + + class ServiceAbc: IService + { + public ServiceAbc(IDependency dep) + { + Dep = dep; + } + + public IDependency Dep { get; } + } internal partial class Composition { @@ -813,8 +825,9 @@ private static void SetupComposition() { // OnDependencyInjection = On DI.Setup("Composition") - .Bind().As(Lifetime.#lifetime#).To(ctx => new Dependency(ctx.OwnerType.Name)) + .Bind().As(Lifetime.#lifetime#).To(ctx => new Dependency(ctx.ConsumerTypes)) .Bind().To() + .Bind("Abc").To() .Root("Service"); } } @@ -834,7 +847,7 @@ public static void Main() // Then result.Success.ShouldBeTrue(result); - result.StdOut.ShouldBe([owner, "Created"], result); + result.StdOut.ShouldBe(consumers.AsEnumerable(), result); } [Fact] diff --git a/tests/Pure.DI.UsageTests/Advanced/DITracingViaSerilogScenario.cs b/tests/Pure.DI.UsageTests/Advanced/DITracingViaSerilogScenario.cs index 904225725..4f2264754 100644 --- a/tests/Pure.DI.UsageTests/Advanced/DITracingViaSerilogScenario.cs +++ b/tests/Pure.DI.UsageTests/Advanced/DITracingViaSerilogScenario.cs @@ -63,7 +63,8 @@ private void Setup() => .Bind().To(ctx => { ctx.Inject("from arg", out Serilog.ILogger logger); - return logger.ForContext(ctx.OwnerType); + var consumers = ctx.ConsumerTypes; + return consumers.Length == 1 ? logger.ForContext(consumers[0]) : logger; }) .Bind().To() @@ -106,6 +107,11 @@ public void Run() var service = composition.Root; // } events.Count.ShouldBe(5); + foreach (var e in events) + { + e.Properties.ContainsKey("SourceContext").ShouldBeTrue(); + } + composition.SaveClassDiagram(); } } \ No newline at end of file diff --git a/tests/Pure.DI.UsageTests/Advanced/SerilogScenario.cs b/tests/Pure.DI.UsageTests/Advanced/SerilogScenario.cs index a995065fd..64e9aa535 100644 --- a/tests/Pure.DI.UsageTests/Advanced/SerilogScenario.cs +++ b/tests/Pure.DI.UsageTests/Advanced/SerilogScenario.cs @@ -62,7 +62,8 @@ private void Setup() => .Bind().To(ctx => { ctx.Inject("from arg", out var logger); - return logger.ForContext(ctx.OwnerType); + var consumers = ctx.ConsumerTypes; + return consumers.Length == 1 ? logger.ForContext(consumers[0]) : logger; }) .Bind().To() @@ -93,6 +94,11 @@ public void Run() var service = composition.Root; // } events.Count.ShouldBe(2); + foreach (var e in events) + { + e.Properties.ContainsKey("SourceContext").ShouldBeTrue(); + } + composition.SaveClassDiagram(); } } \ No newline at end of file