Skip to content

Commit

Permalink
#76 Ability to get/know the type of object for which the factory was …
Browse files Browse the repository at this point in the history
…called
  • Loading branch information
NikolayPianikov committed Dec 17, 2024
1 parent ea62e5a commit 8714dce
Show file tree
Hide file tree
Showing 47 changed files with 235 additions and 208 deletions.
4 changes: 2 additions & 2 deletions readme/async-disposable-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ partial class Composition: IDisposable, IAsyncDisposable
Func<Session> perBlockFunc1 = new Func<Session>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
Composition transientComposition3 = this;
Session localValue89 = new Session(transientComposition3);
return localValue89;
Session localValue93 = new Session(transientComposition3);
return localValue93;
});
return new Program(perBlockFunc1);
}
Expand Down
20 changes: 10 additions & 10 deletions readme/async-root.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ partial class Composition
public Task<IService> GetMyServiceAsync(CancellationToken cancellationToken)
{
TaskFactory<IService> 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<IService>(localCancellationToken39, localTaskCreationOptions40, localTaskContinuationOptions41, localTaskScheduler42);
TaskScheduler localTaskScheduler46 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService>(localCancellationToken43, localTaskCreationOptions44, localTaskContinuationOptions45, localTaskScheduler46);
Func<IService> perBlockFunc1 = new Func<IService>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IService localValue43 = new Service(new Dependency());
return localValue43;
IService localValue47 = new Service(new Dependency());
return localValue47;
});
Task<IService> transientTask0;
// Injects an instance factory
Func<IService> localFactory44 = perBlockFunc1;
Func<IService> localFactory48 = perBlockFunc1;
// Injects a task factory creating and scheduling task objects
TaskFactory<IService> localTaskFactory45 = perBlockTaskFactory2;
TaskFactory<IService> localTaskFactory49 = perBlockTaskFactory2;
// Creates and starts a task using the instance factory
transientTask0 = localTaskFactory45.StartNew(localFactory44);
transientTask0 = localTaskFactory49.StartNew(localFactory48);
return transientTask0;
}
}
Expand Down
10 changes: 5 additions & 5 deletions readme/auto-scoped.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions readme/bind-attribute-for-a-generic-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ partial class Composition
}

IDependency<int> transientIDependency1;
Facade localInstance_1182D12746 = _root._singletonFacade43!;
transientIDependency1 = localInstance_1182D12746.GetDependency<int>();
Facade localInstance_1182D12750 = _root._singletonFacade43!;
transientIDependency1 = localInstance_1182D12750.GetDependency<int>();
return new Service(transientIDependency1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/bind-attribute-with-lifetime-and-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/bind-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions readme/build-up-of-an-existing-generic-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ partial class Composition
{
Guid transientGuid2 = Guid.NewGuid();
Dependency<Guid> transientDependency1;
Dependency<Guid> localDependency52= new Dependency<Guid>();
localDependency52.SetId(transientGuid2);
localDependency52.Name = name;
transientDependency1 = localDependency52;
Dependency<Guid> localDependency56= new Dependency<Guid>();
localDependency56.SetId(transientGuid2);
localDependency56.Name = name;
transientDependency1 = localDependency56;
return new Service<Guid>(transientDependency1);
}
}
Expand Down
8 changes: 4 additions & 4 deletions readme/build-up-of-an-existing-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
11 changes: 7 additions & 4 deletions readme/di-tracing-via-serilog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ partial class Composition
.Bind<Serilog.ILogger>().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<Dependency>()
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -107,7 +109,8 @@ partial class Composition
OnNewInstance<Dependency>(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<IDependency>(transientDependency2, null, Lifetime.Transient));
OnNewInstance<Service>(ref transientService0, null, Lifetime.Transient);
return OnDependencyInjection<IService>(transientService0, null, Lifetime.Transient);
Expand Down
6 changes: 3 additions & 3 deletions readme/exposed-generic-roots-with-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ partial class Composition
}

Integration.IMyGenericService<int> transientIMyGenericService1;
int localId3 = id;
Integration.CompositionWithGenericRootsAndArgsInOtherProject localInstance_1182D1274 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject44!;
transientIMyGenericService1 = localInstance_1182D1274.GetMyService<int>(localId3);
int localId5 = id;
Integration.CompositionWithGenericRootsAndArgsInOtherProject localInstance_1182D1276 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject44!;
transientIMyGenericService1 = localInstance_1182D1276.GetMyService<int>(localId5);
return new Program(transientIMyGenericService1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-generic-roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ partial class Composition
}

Integration.IMyGenericService<int> transientIMyGenericService1;
Integration.CompositionWithGenericRootsInOtherProject localInstance_1182D1272 = _root._singletonCompositionWithGenericRootsInOtherProject43!;
transientIMyGenericService1 = localInstance_1182D1272.GetMyService<int>();
Integration.CompositionWithGenericRootsInOtherProject localInstance_1182D1274 = _root._singletonCompositionWithGenericRootsInOtherProject43!;
transientIMyGenericService1 = localInstance_1182D1274.GetMyService<int>();
return new Program(transientIMyGenericService1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-roots-via-arg.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-roots-via-root-arg.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-roots-with-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/exposed-roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
10 changes: 5 additions & 5 deletions readme/factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions readme/func-with-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions readme/func-with-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ partial class Composition
{
Func<IDependency> perBlockFunc1 = new Func<IDependency>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IDependency localValue57 = new Dependency();
return localValue57;
IDependency localValue61 = new Dependency();
return localValue61;
});
return new Service(perBlockFunc1);
}
Expand Down
4 changes: 2 additions & 2 deletions readme/func.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ partial class Composition
{
Func<IDependency> perBlockFunc1 = new Func<IDependency>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IDependency localValue55 = new Dependency();
return localValue55;
IDependency localValue59 = new Dependency();
return localValue59;
});
return new Service(perBlockFunc1);
}
Expand Down
44 changes: 22 additions & 22 deletions readme/generic-async-composition-roots-with-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,29 @@ partial class Composition
where T2: IDisposable
{
TaskFactory<IService<T2, bool>> 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<IService<T2, bool>>(localCancellationToken71, localTaskCreationOptions72, localTaskContinuationOptions73, localTaskScheduler74);
TaskScheduler localTaskScheduler78 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService<T2, bool>>(localCancellationToken75, localTaskCreationOptions76, localTaskContinuationOptions77, localTaskScheduler78);
Func<IService<T2, bool>> perBlockFunc1 = new Func<IService<T2, bool>>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
OtherService<T2> transientOtherService6;
IDependency<T2> localDependency76 = new Dependency<T2>();
transientOtherService6 = new OtherService<T2>(localDependency76);
IService<T2, bool> localValue75 = transientOtherService6;
return localValue75;
IDependency<T2> localDependency80 = new Dependency<T2>();
transientOtherService6 = new OtherService<T2>(localDependency80);
IService<T2, bool> localValue79 = transientOtherService6;
return localValue79;
});
Task<IService<T2, bool>> transientTask0;
// Injects an instance factory
Func<IService<T2, bool>> localFactory77 = perBlockFunc1;
Func<IService<T2, bool>> localFactory81 = perBlockFunc1;
// Injects a task factory creating and scheduling task objects
TaskFactory<IService<T2, bool>> localTaskFactory78 = perBlockTaskFactory2;
TaskFactory<IService<T2, bool>> localTaskFactory82 = perBlockTaskFactory2;
// Creates and starts a task using the instance factory
transientTask0 = localTaskFactory78.StartNew(localFactory77);
transientTask0 = localTaskFactory82.StartNew(localFactory81);
return transientTask0;
}

Expand All @@ -117,26 +117,26 @@ partial class Composition
where T: struct
{
TaskFactory<IService<T2, T>> 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<IService<T2, T>>(localCancellationToken79, localTaskCreationOptions80, localTaskContinuationOptions81, localTaskScheduler82);
TaskScheduler localTaskScheduler86 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService<T2, T>>(localCancellationToken83, localTaskCreationOptions84, localTaskContinuationOptions85, localTaskScheduler86);
Func<IService<T2, T>> perBlockFunc1 = new Func<IService<T2, T>>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IService<T2, T> localValue83 = new Service<T2, T>(new Dependency<T2>());
return localValue83;
IService<T2, T> localValue87 = new Service<T2, T>(new Dependency<T2>());
return localValue87;
});
Task<IService<T2, T>> transientTask0;
// Injects an instance factory
Func<IService<T2, T>> localFactory84 = perBlockFunc1;
Func<IService<T2, T>> localFactory88 = perBlockFunc1;
// Injects a task factory creating and scheduling task objects
TaskFactory<IService<T2, T>> localTaskFactory85 = perBlockTaskFactory2;
TaskFactory<IService<T2, T>> localTaskFactory89 = perBlockTaskFactory2;
// Creates and starts a task using the instance factory
transientTask0 = localTaskFactory85.StartNew(localFactory84);
transientTask0 = localTaskFactory89.StartNew(localFactory88);
return transientTask0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/generic-composition-roots-with-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ partial class Composition
where T2: IDisposable
{
OtherService<T2> transientOtherService0;
IDependency<T2> localDependency86 = new Dependency<T2>();
transientOtherService0 = new OtherService<T2>(localDependency86);
IDependency<T2> localDependency90 = new Dependency<T2>();
transientOtherService0 = new OtherService<T2>(localDependency90);
return transientOtherService0;
}

Expand Down
4 changes: 2 additions & 2 deletions readme/generic-composition-roots.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ partial class Composition
public IService<T1> GetOtherService<T1>()
{
OtherService<T1> transientOtherService0;
IDependency<T1> localDependency87 = new Dependency<T1>();
transientOtherService0 = new OtherService<T1>(localDependency87);
IDependency<T1> localDependency91 = new Dependency<T1>();
transientOtherService0 = new OtherService<T1>(localDependency91);
return transientOtherService0;
}

Expand Down
Loading

0 comments on commit 8714dce

Please sign in to comment.