Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Dec 16, 2024
1 parent 2af8553 commit 4bf51ea
Show file tree
Hide file tree
Showing 47 changed files with 354 additions and 335 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 localValue85 = new Session(transientComposition3);
return localValue85;
Session localValue89 = new Session(transientComposition3);
return localValue89;
});
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 localCancellationToken35 = cancellationToken;
CancellationToken localCancellationToken39 = cancellationToken;
TaskCreationOptions transientTaskCreationOptions3 = TaskCreationOptions.None;
TaskCreationOptions localTaskCreationOptions36 = transientTaskCreationOptions3;
TaskCreationOptions localTaskCreationOptions40 = transientTaskCreationOptions3;
TaskContinuationOptions transientTaskContinuationOptions4 = TaskContinuationOptions.None;
TaskContinuationOptions localTaskContinuationOptions37 = transientTaskContinuationOptions4;
TaskContinuationOptions localTaskContinuationOptions41 = transientTaskContinuationOptions4;
TaskScheduler transientTaskScheduler5 = TaskScheduler.Default;
TaskScheduler localTaskScheduler38 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService>(localCancellationToken35, localTaskCreationOptions36, localTaskContinuationOptions37, localTaskScheduler38);
TaskScheduler localTaskScheduler42 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService>(localCancellationToken39, localTaskCreationOptions40, localTaskContinuationOptions41, localTaskScheduler42);
Func<IService> perBlockFunc1 = new Func<IService>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IService localValue39 = new Service(new Dependency());
return localValue39;
IService localValue43 = new Service(new Dependency());
return localValue43;
});
Task<IService> transientTask0;
// Injects an instance factory
Func<IService> localFactory40 = perBlockFunc1;
Func<IService> localFactory44 = perBlockFunc1;
// Injects a task factory creating and scheduling task objects
TaskFactory<IService> localTaskFactory41 = perBlockTaskFactory2;
TaskFactory<IService> localTaskFactory45 = perBlockTaskFactory2;
// Creates and starts a task using the instance factory
transientTask0 = localTaskFactory41.StartNew(localFactory40);
transientTask0 = localTaskFactory45.StartNew(localFactory44);
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 localBaseComposition87 = transientComposition3;
Composition localBaseComposition91 = transientComposition3;
// Creates a session
var localSession88= new Composition(localBaseComposition87);
var localSession92= new Composition(localBaseComposition91);
// Provides a root
transientIService2 = localSession88.SessionRoot;
IService localValue86 = transientIService2;
return localValue86;
transientIService2 = localSession92.SessionRoot;
IService localValue90 = transientIService2;
return localValue90;
});
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_1182D12742 = _root._singletonFacade43!;
transientIDependency1 = localInstance_1182D12742.GetDependency<int>();
Facade localInstance_1182D12746 = _root._singletonFacade43!;
transientIDependency1 = localInstance_1182D12746.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_1182D12744 = _root._singletonFacade43!;
_root._singletonIDependency0 = localInstance_1182D12744.Dependency;
Facade localInstance_1182D12748 = _root._singletonFacade43!;
_root._singletonIDependency0 = localInstance_1182D12748.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_1182D12743 = _root._singletonFacade43!;
transientIDependency1 = localInstance_1182D12743.Dependency;
Facade localInstance_1182D12747 = _root._singletonFacade43!;
transientIDependency1 = localInstance_1182D12747.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> localDependency48= new Dependency<Guid>();
localDependency48.SetId(transientGuid2);
localDependency48.Name = name;
transientDependency1 = localDependency48;
Dependency<Guid> localDependency52= new Dependency<Guid>();
localDependency52.SetId(transientGuid2);
localDependency52.Name = name;
transientDependency1 = localDependency52;
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 localDependency45= new Dependency();
localDependency45.SetId(transientGuid2);
localDependency45.Name = name;
transientDependency1 = localDependency45;
var localDependency49= new Dependency();
localDependency49.SetId(transientGuid2);
localDependency49.Name = name;
transientDependency1 = localDependency49;
return new Service(transientDependency1);
}
}
Expand Down
100 changes: 28 additions & 72 deletions readme/di-tracing-via-serilog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IService

class Service : IService
{
public Service(ILogger<Service> log, IDependency dependency)
public Service(Serilog.ILogger log, IDependency dependency)
{
Dependency = dependency;
log.Information("Created");
Expand All @@ -24,17 +24,6 @@ class Service : IService
public IDependency Dependency { get; }
}

interface ILogger<T>: Serilog.ILogger;

class Logger<T>(Serilog.ILogger logger) : ILogger<T>
{
private readonly Serilog.ILogger _logger =
logger.ForContext(typeof(T));

public void Write(LogEvent logEvent) =>
_logger.Write(logEvent);
}

partial class Composition
{
private void Setup() =>
Expand All @@ -46,12 +35,16 @@ partial class Composition
.Hint(Hint.OnNewInstanceImplementationTypeNameRegularExpression, "^((?!Logger).)*$")
.Hint(Hint.OnDependencyInjectionContractTypeNameRegularExpression, "^((?!Logger).)*$")

.Arg<Serilog.ILogger>("logger")
.Bind().As(Lifetime.Singleton).To<Logger<TT>>()
.Arg<Serilog.ILogger>("logger", "from arg")
.Bind<Serilog.ILogger>().To(ctx =>
{
ctx.Inject("from arg", out Serilog.ILogger logger);
return logger.ForContext(ctx.OwnerType);
})

.Bind().To<Dependency>()
.Bind().To<Service>()
.Root<ILogger<Composition>>(nameof(Log), kind: RootKinds.Private)
.Root<Serilog.ILogger>(nameof(Log), kind: RootKinds.Private)
.Root<IService>(nameof(Root));

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -77,10 +70,6 @@ The following partial class will be generated:
partial class Composition
{
private readonly Composition _root;
private readonly Lock _lock;

private Logger<Service>? _singletonLogger48;
private Logger<Composition>? _singletonLogger47;

private readonly Serilog.ILogger _argLogger;

Expand All @@ -89,57 +78,39 @@ partial class Composition
{
_argLogger = logger ?? throw new ArgumentNullException(nameof(logger));
_root = this;
_lock = new Lock();
}

internal Composition(Composition parentScope)
{
_root = (parentScope ?? throw new ArgumentNullException(nameof(parentScope)))._root;
_argLogger = _root._argLogger;
_lock = _root._lock;
}

public IService Root
private Serilog.ILogger Log
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
Dependency transientDependency1 = new Dependency();
OnNewInstance<Dependency>(ref transientDependency1, null, Lifetime.Transient);
if (_root._singletonLogger48 is null)
{
using (_lock.EnterScope())
{
if (_root._singletonLogger48 is null)
{
_root._singletonLogger48 = new Logger<Service>(_argLogger);
}
}
}

Service transientService0 = new Service(_root._singletonLogger48!, OnDependencyInjection<IDependency>(transientDependency1, null, Lifetime.Transient));
OnNewInstance<Service>(ref transientService0, null, Lifetime.Transient);
return OnDependencyInjection<IService>(transientService0, null, Lifetime.Transient);
Serilog.ILogger transientILogger0;
Serilog.ILogger localLogger1 = _argLogger;
transientILogger0 = localLogger1.ForContext(typeof(Serilog.ILogger));
return transientILogger0;
}
}

private ILogger<Composition> Log
public IService Root
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (_root._singletonLogger47 is null)
{
using (_lock.EnterScope())
{
if (_root._singletonLogger47 is null)
{
_root._singletonLogger47 = new Logger<Composition>(_argLogger);
}
}
}

return _root._singletonLogger47!;
Dependency transientDependency2 = new Dependency();
OnNewInstance<Dependency>(ref transientDependency2, null, Lifetime.Transient);
Serilog.ILogger transientILogger1;
Serilog.ILogger localLogger0 = _argLogger;
transientILogger1 = localLogger0.ForContext(typeof(Service));
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 All @@ -160,19 +131,16 @@ Class diagram:
---
classDiagram
Service --|> IService
LoggerᐸCompositionᐳ --|> ILoggerᐸCompositionᐳ
LoggerᐸServiceᐳ --|> ILoggerᐸServiceᐳ
Dependency --|> IDependency
Composition ..> Service : IService Root
Composition ..> LoggerᐸCompositionᐳ : ILoggerᐸCompositionᐳ Log
Service o-- "Singleton" LoggerᐸServiceᐳ : ILoggerᐸServiceᐳ
Composition ..> ILogger : ILogger Log
Service *-- ILogger : ILogger
Service *-- Dependency : IDependency
LoggerᐸCompositionᐳ o-- ILogger : Argument "logger"
LoggerᐸServiceᐳ o-- ILogger : Argument "logger"
ILogger o-- ILogger : "from arg" Argument "logger"
namespace Pure.DI.UsageTests.Advanced.DITracingViaSerilogScenario {
class Composition {
<<partial>>
-ILoggerᐸCompositionᐳ Log
-ILogger Log
+IService Root
}
class Dependency {
Expand All @@ -181,28 +149,16 @@ classDiagram
class IDependency {
<<interface>>
}
class ILoggerᐸCompositionᐳ {
<<interface>>
}
class ILoggerᐸServiceᐳ {
<<interface>>
}
class IService {
<<interface>>
}
class LoggerᐸCompositionᐳ {
+Logger(ILogger logger)
}
class LoggerᐸServiceᐳ {
+Logger(ILogger logger)
}
class Service {
+Service(ILoggerᐸServiceᐳ log, IDependency dependency)
+Service(ILogger log, IDependency dependency)
}
}
namespace Serilog {
class ILogger {
<<interface>>
<<interface>>
}
}
```
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 localId1 = id;
Integration.CompositionWithGenericRootsAndArgsInOtherProject localInstance_1182D1272 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject44!;
transientIMyGenericService1 = localInstance_1182D1272.GetMyService<int>(localId1);
int localId3 = id;
Integration.CompositionWithGenericRootsAndArgsInOtherProject localInstance_1182D1274 = _root._singletonCompositionWithGenericRootsAndArgsInOtherProject44!;
transientIMyGenericService1 = localInstance_1182D1274.GetMyService<int>(localId3);
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_1182D1270 = _root._singletonCompositionWithGenericRootsInOtherProject43!;
transientIMyGenericService1 = localInstance_1182D1270.GetMyService<int>();
Integration.CompositionWithGenericRootsInOtherProject localInstance_1182D1272 = _root._singletonCompositionWithGenericRootsInOtherProject43!;
transientIMyGenericService1 = localInstance_1182D1272.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_1182D1274 = _argBaseComposition;
transientIMyService1 = localInstance_1182D1274.MyService;
Integration.CompositionInOtherProject localInstance_1182D1276 = _argBaseComposition;
transientIMyService1 = localInstance_1182D1276.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_1182D1275 = baseComposition;
transientIMyService1 = localInstance_1182D1275.MyService;
Integration.CompositionInOtherProject localInstance_1182D1277 = baseComposition;
transientIMyService1 = localInstance_1182D1277.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_1182D1276 = _root._singletonCompositionWithTagsInOtherProject43!;
transientIMyService1 = localInstance_1182D1276.MyService;
Integration.CompositionWithTagsInOtherProject localInstance_1182D1278 = _root._singletonCompositionWithTagsInOtherProject43!;
transientIMyService1 = localInstance_1182D1278.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_1182D1273 = _root._singletonCompositionInOtherProject43!;
transientIMyService1 = localInstance_1182D1273.MyService;
Integration.CompositionInOtherProject localInstance_1182D1275 = _root._singletonCompositionInOtherProject43!;
transientIMyService1 = localInstance_1182D1275.MyService;
return new Program(transientIMyService1);
}
}
Expand Down
Loading

0 comments on commit 4bf51ea

Please sign in to comment.