Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Mar 17, 2024
1 parent c923ba3 commit e4ee621
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
16 changes: 8 additions & 8 deletions readme/tag-unique.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ classDiagram
+ object Resolve(Type type, object? tag)
}
class IEnumerableᐸIDependencyᐸStringᐳᐳ
AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : 16e12d33-c99c-48ed-a87d-df2ef404d031
AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : 66b0ed2b-88dc-4f2a-a035-673c85f19517
class AbcDependencyᐸStringᐳ {
+AbcDependency()
}
XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : 366091bb-5db5-4259-9637-fd5fb7a97653
XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : 09c3dadf-4b17-451e-9456-1ee7426544ec
class XyzDependencyᐸStringᐳ {
+XyzDependency()
}
Expand All @@ -64,8 +64,8 @@ classDiagram
class IServiceᐸStringᐳ {
<<abstract>>
}
IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : 16e12d33-c99c-48ed-a87d-df2ef404d031 IDependencyᐸStringᐳ
IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : 366091bb-5db5-4259-9637-fd5fb7a97653 IDependencyᐸStringᐳ
IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : 66b0ed2b-88dc-4f2a-a035-673c85f19517 IDependencyᐸStringᐳ
IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : 09c3dadf-4b17-451e-9456-1ee7426544ec IDependencyᐸStringᐳ
Composition ..> ServiceᐸStringᐳ : IServiceᐸStringᐳ Root
ServiceᐸStringᐳ o-- "PerBlock" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ
```
Expand Down Expand Up @@ -157,11 +157,11 @@ partial class Composition
" + object Resolve(Type type, object? tag)\n" +
" }\n" +
" class IEnumerableᐸIDependencyᐸStringᐳᐳ\n" +
" AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : 16e12d33-c99c-48ed-a87d-df2ef404d031 \n" +
" AbcDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : 66b0ed2b-88dc-4f2a-a035-673c85f19517 \n" +
" class AbcDependencyᐸStringᐳ {\n" +
" +AbcDependency()\n" +
" }\n" +
" XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : 366091bb-5db5-4259-9637-fd5fb7a97653 \n" +
" XyzDependencyᐸStringᐳ --|> IDependencyᐸStringᐳ : 09c3dadf-4b17-451e-9456-1ee7426544ec \n" +
" class XyzDependencyᐸStringᐳ {\n" +
" +XyzDependency()\n" +
" }\n" +
Expand All @@ -175,8 +175,8 @@ partial class Composition
" class IServiceᐸStringᐳ {\n" +
" <<abstract>>\n" +
" }\n" +
" IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : 16e12d33-c99c-48ed-a87d-df2ef404d031 IDependencyᐸStringᐳ\n" +
" IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : 366091bb-5db5-4259-9637-fd5fb7a97653 IDependencyᐸStringᐳ\n" +
" IEnumerableᐸIDependencyᐸStringᐳᐳ *-- AbcDependencyᐸStringᐳ : 66b0ed2b-88dc-4f2a-a035-673c85f19517 IDependencyᐸStringᐳ\n" +
" IEnumerableᐸIDependencyᐸStringᐳᐳ *-- XyzDependencyᐸStringᐳ : 09c3dadf-4b17-451e-9456-1ee7426544ec IDependencyᐸStringᐳ\n" +
" Composition ..> ServiceᐸStringᐳ : IServiceᐸStringᐳ Root\n" +
" ServiceᐸStringᐳ o-- \"PerBlock\" IEnumerableᐸIDependencyᐸStringᐳᐳ : IEnumerableᐸIDependencyᐸStringᐳᐳ";
}
Expand Down
38 changes: 19 additions & 19 deletions readme/tracking-disposable-instances-per-a-composition-root.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### Tracking disposable instances per a composition root

[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Hints/TrackingDisposableInstances2Scenario.cs)
[![CSharp](https://img.shields.io/badge/C%23-code-blue.svg)](../tests/Pure.DI.UsageTests/Hints/TrackingDisposableInstancesPerRootScenario.cs)

```c#
interface IDependency
Expand Down Expand Up @@ -37,7 +37,7 @@ internal static class Disposables
public void Dispose() { }
}

private class CombinedDisposable(Stack<IDisposable> disposables)
internal class CombinedDisposable(Stack<IDisposable> disposables)
: IDisposable
{
public void Dispose()
Expand Down Expand Up @@ -81,7 +81,7 @@ partial class Composition
object? tag,
Lifetime lifetime)
{
if (value is IDisposable disposable)
if (value is IDisposable disposable && value is not Disposables.CombinedDisposable)
{
var disposables = _disposables.GetOrAdd(
Environment.CurrentManagedThreadId,
Expand All @@ -96,15 +96,15 @@ var composition = new Composition();
var root1 = composition.Root;
var root2 = composition.Root;

root1.combinedDisposables.Dispose();
root2.combinedDisposables.Dispose();

// Checks that the disposable instances
// associated with root1 have been disposed of
root1.service.Dependency.IsDisposed.ShouldBeTrue();
root2.service.Dependency.IsDisposed.ShouldBeTrue();

// Checks that the disposable instances
// associated with root2 have not been disposed of
root2.service.Dependency.IsDisposed.ShouldBeFalse();
root1.service.Dependency.IsDisposed.ShouldBeFalse();
```

<details open>
Expand Down Expand Up @@ -163,18 +163,18 @@ partial class Composition
_rootM03D17di = baseComposition._rootM03D17di;
}

public (Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables) Root
public (Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables) Root
{
get
{
Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.Dependency transientM03D17di3_Dependency = new Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.Dependency();
OnNewInstance<Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.Dependency>(ref transientM03D17di3_Dependency, null, Pure.DI.Lifetime.Transient);
Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.Dependency transientM03D17di3_Dependency = new Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.Dependency();
OnNewInstance<Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.Dependency>(ref transientM03D17di3_Dependency, null, Pure.DI.Lifetime.Transient);
System.IDisposable transientM03D17di2_IDisposable = _disposables.TryRemove(Environment.CurrentManagedThreadId, out var disposables_M03D17di1) ? disposables_M03D17di1.Combine() : Disposables.Empty;
OnNewInstance<System.IDisposable>(ref transientM03D17di2_IDisposable, null, Pure.DI.Lifetime.Transient);
Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.Service transientM03D17di1_Service = new Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.Service(transientM03D17di3_Dependency);
OnNewInstance<Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.Service>(ref transientM03D17di1_Service, null, Pure.DI.Lifetime.Transient);
(Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables) transientM03D17di0_ValueTuple = (transientM03D17di1_Service, transientM03D17di2_IDisposable);
OnNewInstance<(Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables)>(ref transientM03D17di0_ValueTuple, null, Pure.DI.Lifetime.Transient);
Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.Service transientM03D17di1_Service = new Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.Service(transientM03D17di3_Dependency);
OnNewInstance<Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.Service>(ref transientM03D17di1_Service, null, Pure.DI.Lifetime.Transient);
(Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables) transientM03D17di0_ValueTuple = (transientM03D17di1_Service, transientM03D17di2_IDisposable);
OnNewInstance<(Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables)>(ref transientM03D17di0_ValueTuple, null, Pure.DI.Lifetime.Transient);
return transientM03D17di0_ValueTuple;
}
}
Expand Down Expand Up @@ -262,13 +262,13 @@ partial class Composition
static Composition()
{
var valResolverM03D17di_0000 = new ResolverM03D17di_0000();
ResolverM03D17di<(Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables)>.Value = valResolverM03D17di_0000;
ResolverM03D17di<(Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables)>.Value = valResolverM03D17di_0000;
_bucketsM03D17di = global::Pure.DI.Buckets<global::System.Type, global::Pure.DI.IResolver<Composition, object>>.Create(
1,
out _bucketSizeM03D17di,
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Composition, object>>[1]
{
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Composition, object>>(typeof((Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables)), valResolverM03D17di_0000)
new global::Pure.DI.Pair<global::System.Type, global::Pure.DI.IResolver<Composition, object>>(typeof((Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables)), valResolverM03D17di_0000)
});
}

Expand All @@ -287,21 +287,21 @@ partial class Composition
}
}

private sealed class ResolverM03D17di_0000: global::Pure.DI.IResolver<Composition, (Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables)>, global::Pure.DI.IResolver<Composition, object>
private sealed class ResolverM03D17di_0000: global::Pure.DI.IResolver<Composition, (Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables)>, global::Pure.DI.IResolver<Composition, object>
{
public (Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables) Resolve(Composition composition)
public (Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables) Resolve(Composition composition)
{
return composition.Root;
}

public (Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables) ResolveByTag(Composition composition, object tag)
public (Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables) ResolveByTag(Composition composition, object tag)
{
switch (tag)
{
case null:
return composition.Root;
}
throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type (Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario.IService service, System.IDisposable combinedDisposables).");
throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type (Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario.IService service, System.IDisposable combinedDisposables).");
}
object global::Pure.DI.IResolver<Composition, object>.Resolve(Composition composition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// ReSharper disable UnusedParameterInPartialMethod
// ReSharper disable ArrangeTypeModifiers
// ReSharper disable InvertIf
namespace Pure.DI.UsageTests.Hints.TrackingDisposableInstances2Scenario;
namespace Pure.DI.UsageTests.Hints.TrackingDisposableInstancesPerRootScenario;

using System.Collections.Concurrent;
using Xunit;
Expand Down Expand Up @@ -49,7 +49,7 @@ private class EmptyDisposable : IDisposable
public void Dispose() { }
}

private class CombinedDisposable(Stack<IDisposable> disposables)
internal class CombinedDisposable(Stack<IDisposable> disposables)
: IDisposable
{
public void Dispose()
Expand Down Expand Up @@ -93,7 +93,7 @@ partial void OnNewInstance<T>(
object? tag,
Lifetime lifetime)
{
if (value is IDisposable disposable)
if (value is IDisposable disposable && value is not Disposables.CombinedDisposable)
{
var disposables = _disposables.GetOrAdd(
Environment.CurrentManagedThreadId,
Expand All @@ -115,15 +115,15 @@ public void Run()
var root1 = composition.Root;
var root2 = composition.Root;

root1.combinedDisposables.Dispose();
root2.combinedDisposables.Dispose();

// Checks that the disposable instances
// associated with root1 have been disposed of
root1.service.Dependency.IsDisposed.ShouldBeTrue();
root2.service.Dependency.IsDisposed.ShouldBeTrue();

// Checks that the disposable instances
// associated with root2 have not been disposed of
root2.service.Dependency.IsDisposed.ShouldBeFalse();
root1.service.Dependency.IsDisposed.ShouldBeFalse();
// }
new Composition().SaveClassDiagram();
}
Expand Down

0 comments on commit e4ee621

Please sign in to comment.