Skip to content

Commit

Permalink
Adds the Own/IOwn API class to Pure.DI.Abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Nov 21, 2024
1 parent edeec6f commit 7aacfca
Show file tree
Hide file tree
Showing 56 changed files with 1,048 additions and 352 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ dotnet run
- [A few partial classes](readme/a-few-partial-classes.md)
- [Tracking disposable instances per a composition root](readme/tracking-disposable-instances-per-a-composition-root.md)
- [Tracking disposable instances in delegates](readme/tracking-disposable-instances-in-delegates.md)
- [Tracking disposable instances using pre-built classes](readme/tracking-disposable-instances-using-pre-built-classes.md)
- [Tracking disposable instances with different lifetimes](readme/tracking-disposable-instances-with-different-lifetimes.md)
- [Tracking async disposable instances per a composition root](readme/tracking-async-disposable-instances-per-a-composition-root.md)
- [Tracking async disposable instances in delegates](readme/tracking-async-disposable-instances-in-delegates.md)
Expand Down
24 changes: 12 additions & 12 deletions readme/accumulators.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ partial class Composition
private readonly Composition _root;
private readonly Lock _lock;

private XyzDependency? _singletonXyzDependency41;
private XyzDependency? _singletonXyzDependency43;

[OrdinalAttribute(20)]
public Composition()
Expand All @@ -69,34 +69,34 @@ partial class Composition
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
var accumulator44 = new MyAccumulator();
var accumulator46 = new MyAccumulator();
AbcDependency perBlockAbcDependency4 = new AbcDependency();
if (_root._singletonXyzDependency41 is null)
if (_root._singletonXyzDependency43 is null)
{
using (_lock.EnterScope())
{
if (_root._singletonXyzDependency41 is null)
if (_root._singletonXyzDependency43 is null)
{
XyzDependency _singletonXyzDependency41Temp;
_singletonXyzDependency41Temp = new XyzDependency();
accumulator44.Add(_singletonXyzDependency41Temp);
XyzDependency _singletonXyzDependency43Temp;
_singletonXyzDependency43Temp = new XyzDependency();
accumulator46.Add(_singletonXyzDependency43Temp);
Thread.MemoryBarrier();
_root._singletonXyzDependency41 = _singletonXyzDependency41Temp;
_root._singletonXyzDependency43 = _singletonXyzDependency43Temp;
}
}
}

AbcDependency transientAbcDependency3 = new AbcDependency();
using (_lock.EnterScope())
{
accumulator44.Add(transientAbcDependency3);
accumulator46.Add(transientAbcDependency3);
}
Service transientService1 = new Service(transientAbcDependency3, _root._singletonXyzDependency41!, perBlockAbcDependency4);
Service transientService1 = new Service(transientAbcDependency3, _root._singletonXyzDependency43!, perBlockAbcDependency4);
using (_lock.EnterScope())
{
accumulator44.Add(transientService1);
accumulator46.Add(transientService1);
}
return (transientService1, accumulator44);
return (transientService1, accumulator46);
}
}

Expand Down
20 changes: 10 additions & 10 deletions readme/async-disposable-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ partial class Composition: IDisposable, IAsyncDisposable
private object[] _disposables;
private int _disposeIndex;

private Dependency? _scopedDependency39;
private Dependency? _scopedDependency41;

[OrdinalAttribute(20)]
public Composition()
Expand All @@ -115,19 +115,19 @@ partial class Composition: IDisposable, IAsyncDisposable
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (_scopedDependency39 is null)
if (_scopedDependency41 is null)
{
using (_lock.EnterScope())
{
if (_scopedDependency39 is null)
if (_scopedDependency41 is null)
{
_scopedDependency39 = new Dependency();
_disposables[_disposeIndex++] = _scopedDependency39;
_scopedDependency41 = new Dependency();
_disposables[_disposeIndex++] = _scopedDependency41;
}
}
}

return new Service(_scopedDependency39!);
return new Service(_scopedDependency41!);
}
}

Expand All @@ -139,8 +139,8 @@ partial class Composition: IDisposable, IAsyncDisposable
Func<Session> perBlockFunc1 = new Func<Session>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
Composition transientComposition3 = this;
Session localValue72 = new Session(transientComposition3);
return localValue72;
Session localValue78 = new Session(transientComposition3);
return localValue78;
});
return new Program(perBlockFunc1);
}
Expand All @@ -156,7 +156,7 @@ partial class Composition: IDisposable, IAsyncDisposable
_disposeIndex = 0;
disposables = _disposables;
_disposables = new object[1];
_scopedDependency39 = null;
_scopedDependency41 = null;
}

while (disposeIndex-- > 0)
Expand Down Expand Up @@ -194,7 +194,7 @@ partial class Composition: IDisposable, IAsyncDisposable
_disposeIndex = 0;
disposables = _disposables;
_disposables = new object[1];
_scopedDependency39 = null;
_scopedDependency41 = null;
}
finally
{
Expand Down
16 changes: 8 additions & 8 deletions readme/async-disposable-singleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ partial class Composition: IDisposable, IAsyncDisposable
private object[] _disposables;
private int _disposeIndex;

private Dependency? _singletonDependency39;
private Dependency? _singletonDependency41;

[OrdinalAttribute(20)]
public Composition()
Expand All @@ -81,19 +81,19 @@ partial class Composition: IDisposable, IAsyncDisposable
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (_root._singletonDependency39 is null)
if (_root._singletonDependency41 is null)
{
using (_lock.EnterScope())
{
if (_root._singletonDependency39 is null)
if (_root._singletonDependency41 is null)
{
_root._singletonDependency39 = new Dependency();
_root._disposables[_root._disposeIndex++] = _root._singletonDependency39;
_root._singletonDependency41 = new Dependency();
_root._disposables[_root._disposeIndex++] = _root._singletonDependency41;
}
}
}

return new Service(_root._singletonDependency39!);
return new Service(_root._singletonDependency41!);
}
}

Expand All @@ -107,7 +107,7 @@ partial class Composition: IDisposable, IAsyncDisposable
_disposeIndex = 0;
disposables = _disposables;
_disposables = new object[1];
_singletonDependency39 = null;
_singletonDependency41 = null;
}

while (disposeIndex-- > 0)
Expand Down Expand Up @@ -145,7 +145,7 @@ partial class Composition: IDisposable, IAsyncDisposable
_disposeIndex = 0;
disposables = _disposables;
_disposables = new object[1];
_singletonDependency39 = null;
_singletonDependency41 = null;
}
finally
{
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 localCancellationToken23 = cancellationToken;
CancellationToken localCancellationToken29 = cancellationToken;
TaskCreationOptions transientTaskCreationOptions3 = TaskCreationOptions.None;
TaskCreationOptions localTaskCreationOptions24 = transientTaskCreationOptions3;
TaskCreationOptions localTaskCreationOptions30 = transientTaskCreationOptions3;
TaskContinuationOptions transientTaskContinuationOptions4 = TaskContinuationOptions.None;
TaskContinuationOptions localTaskContinuationOptions25 = transientTaskContinuationOptions4;
TaskContinuationOptions localTaskContinuationOptions31 = transientTaskContinuationOptions4;
TaskScheduler transientTaskScheduler5 = TaskScheduler.Default;
TaskScheduler localTaskScheduler26 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService>(localCancellationToken23, localTaskCreationOptions24, localTaskContinuationOptions25, localTaskScheduler26);
TaskScheduler localTaskScheduler32 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService>(localCancellationToken29, localTaskCreationOptions30, localTaskContinuationOptions31, localTaskScheduler32);
Func<IService> perBlockFunc1 = new Func<IService>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IService localValue27 = new Service(new Dependency());
return localValue27;
IService localValue33 = new Service(new Dependency());
return localValue33;
});
Task<IService> transientTask0;
// Injects an instance factory
Func<IService> localFactory28 = perBlockFunc1;
Func<IService> localFactory34 = perBlockFunc1;
// Injects a task factory creating and scheduling task objects
TaskFactory<IService> localTaskFactory29 = perBlockTaskFactory2;
TaskFactory<IService> localTaskFactory35 = perBlockTaskFactory2;
// Creates and starts a task using the instance factory
transientTask0 = localTaskFactory29.StartNew(localFactory28);
transientTask0 = localTaskFactory35.StartNew(localFactory34);
return transientTask0;
}
}
Expand Down
20 changes: 10 additions & 10 deletions readme/auto-scoped.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ partial class Composition
private readonly Composition _root;
private readonly Lock _lock;

private Dependency? _scopedDependency39;
private Dependency? _scopedDependency41;

[OrdinalAttribute(20)]
public Composition()
Expand All @@ -100,12 +100,12 @@ partial class Composition
Composition transientComposition3 = this;
IService transientIService2;
// Injects a base composition
Composition localBaseComposition74 = transientComposition3;
Composition localBaseComposition80 = transientComposition3;
// Creates a session
var localSession75= new Composition(localBaseComposition74);
transientIService2 = localSession75.SessionRoot;
IService localValue73 = transientIService2;
return localValue73;
var localSession81= new Composition(localBaseComposition80);
transientIService2 = localSession81.SessionRoot;
IService localValue79 = transientIService2;
return localValue79;
});
return new Program(perBlockFunc1);
}
Expand All @@ -116,18 +116,18 @@ partial class Composition
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (_scopedDependency39 is null)
if (_scopedDependency41 is null)
{
using (_lock.EnterScope())
{
if (_scopedDependency39 is null)
if (_scopedDependency41 is null)
{
_scopedDependency39 = new Dependency();
_scopedDependency41 = new Dependency();
}
}
}

return new Service(_scopedDependency39!);
return new Service(_scopedDependency41!);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions readme/bind-attribute-for-a-generic-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ partial class Composition
private readonly Composition _root;
private readonly Lock _lock;

private Facade? _singletonFacade39;
private Facade? _singletonFacade41;

[OrdinalAttribute(20)]
public Composition()
Expand All @@ -72,20 +72,20 @@ partial class Composition
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (_root._singletonFacade39 is null)
if (_root._singletonFacade41 is null)
{
using (_lock.EnterScope())
{
if (_root._singletonFacade39 is null)
if (_root._singletonFacade41 is null)
{
_root._singletonFacade39 = new Facade();
_root._singletonFacade41 = new Facade();
}
}
}

IDependency<int> transientIDependency1;
Facade localInstance_1182D12730 = _root._singletonFacade39!;
transientIDependency1 = localInstance_1182D12730.GetDependency<int>();
Facade localInstance_1182D12736 = _root._singletonFacade41!;
transientIDependency1 = localInstance_1182D12736.GetDependency<int>();
return new Service(transientIDependency1);
}
}
Expand Down
10 changes: 5 additions & 5 deletions readme/bind-attribute-with-lifetime-and-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ partial class Composition
private readonly Lock _lock;

private IDependency? _singletonIDependency0;
private Facade? _singletonFacade39;
private Facade? _singletonFacade41;

[OrdinalAttribute(20)]
public Composition()
Expand All @@ -79,13 +79,13 @@ partial class Composition
{
if (_root._singletonIDependency0 is null)
{
if (_root._singletonFacade39 is null)
if (_root._singletonFacade41 is null)
{
_root._singletonFacade39 = new Facade();
_root._singletonFacade41 = new Facade();
}

Facade localInstance_1182D12732 = _root._singletonFacade39!;
_root._singletonIDependency0 = localInstance_1182D12732.Dependency;
Facade localInstance_1182D12738 = _root._singletonFacade41!;
_root._singletonIDependency0 = localInstance_1182D12738.Dependency;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions readme/bind-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ partial class Composition
private readonly Composition _root;
private readonly Lock _lock;

private Facade? _singletonFacade39;
private Facade? _singletonFacade41;

[OrdinalAttribute(20)]
public Composition()
Expand All @@ -76,20 +76,20 @@ partial class Composition
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (_root._singletonFacade39 is null)
if (_root._singletonFacade41 is null)
{
using (_lock.EnterScope())
{
if (_root._singletonFacade39 is null)
if (_root._singletonFacade41 is null)
{
_root._singletonFacade39 = new Facade();
_root._singletonFacade41 = new Facade();
}
}
}

IDependency transientIDependency1;
Facade localInstance_1182D12731 = _root._singletonFacade39!;
transientIDependency1 = localInstance_1182D12731.Dependency;
Facade localInstance_1182D12737 = _root._singletonFacade41!;
transientIDependency1 = localInstance_1182D12737.Dependency;
return new Service(transientIDependency1);
}
}
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 localDependency33= new Dependency();
localDependency33.SetId(transientGuid2);
localDependency33.Name = name;
transientDependency1 = localDependency33;
var localDependency39= new Dependency();
localDependency39.SetId(transientGuid2);
localDependency39.Name = name;
transientDependency1 = localDependency39;
return new Service(transientDependency1);
}
}
Expand Down
Loading

0 comments on commit 7aacfca

Please sign in to comment.