Skip to content

Commit

Permalink
Add sample "Tracking disposable instances with different lifetimes"
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Nov 17, 2024
1 parent 3dad52b commit ffe65e7
Show file tree
Hide file tree
Showing 23 changed files with 557 additions and 91 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 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)
- [Exposed roots](readme/exposed-roots.md)
Expand Down
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 localValue65 = new Session(transientComposition3);
return localValue65;
Session localValue71 = new Session(transientComposition3);
return localValue71;
});
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 localCancellationToken17 = cancellationToken;
CancellationToken localCancellationToken23 = cancellationToken;
TaskCreationOptions transientTaskCreationOptions3 = TaskCreationOptions.None;
TaskCreationOptions localTaskCreationOptions18 = transientTaskCreationOptions3;
TaskCreationOptions localTaskCreationOptions24 = transientTaskCreationOptions3;
TaskContinuationOptions transientTaskContinuationOptions4 = TaskContinuationOptions.None;
TaskContinuationOptions localTaskContinuationOptions19 = transientTaskContinuationOptions4;
TaskContinuationOptions localTaskContinuationOptions25 = transientTaskContinuationOptions4;
TaskScheduler transientTaskScheduler5 = TaskScheduler.Default;
TaskScheduler localTaskScheduler20 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService>(localCancellationToken17, localTaskCreationOptions18, localTaskContinuationOptions19, localTaskScheduler20);
TaskScheduler localTaskScheduler26 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService>(localCancellationToken23, localTaskCreationOptions24, localTaskContinuationOptions25, localTaskScheduler26);
Func<IService> perBlockFunc1 = new Func<IService>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IService localValue21 = new Service(new Dependency());
return localValue21;
IService localValue27 = new Service(new Dependency());
return localValue27;
});
Task<IService> transientTask0;
// Injects an instance factory
Func<IService> localFactory22 = perBlockFunc1;
Func<IService> localFactory28 = perBlockFunc1;
// Injects a task factory creating and scheduling task objects
TaskFactory<IService> localTaskFactory23 = perBlockTaskFactory2;
TaskFactory<IService> localTaskFactory29 = perBlockTaskFactory2;
// Creates and starts a task using the instance factory
transientTask0 = localTaskFactory23.StartNew(localFactory22);
transientTask0 = localTaskFactory29.StartNew(localFactory28);
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 @@ -100,12 +100,12 @@ partial class Composition
Composition transientComposition3 = this;
IService transientIService2;
// Injects a base composition
Composition localBaseComposition67 = transientComposition3;
Composition localBaseComposition73 = transientComposition3;
// Creates a session
var localSession68= new Composition(localBaseComposition67);
transientIService2 = localSession68.SessionRoot;
IService localValue66 = transientIService2;
return localValue66;
var localSession74= new Composition(localBaseComposition73);
transientIService2 = localSession74.SessionRoot;
IService localValue72 = transientIService2;
return localValue72;
});
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_1182D12724 = _root._singletonFacade39!;
transientIDependency1 = localInstance_1182D12724.GetDependency<int>();
Facade localInstance_1182D12730 = _root._singletonFacade39!;
transientIDependency1 = localInstance_1182D12730.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._singletonFacade39 = new Facade();
}

Facade localInstance_1182D12726 = _root._singletonFacade39!;
_root._singletonIDependency0 = localInstance_1182D12726.Dependency;
Facade localInstance_1182D12732 = _root._singletonFacade39!;
_root._singletonIDependency0 = localInstance_1182D12732.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_1182D12725 = _root._singletonFacade39!;
transientIDependency1 = localInstance_1182D12725.Dependency;
Facade localInstance_1182D12731 = _root._singletonFacade39!;
transientIDependency1 = localInstance_1182D12731.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 @@ -78,10 +78,10 @@ partial class Composition
{
Guid transientGuid2 = Guid.NewGuid();
Dependency transientDependency1;
var localDependency27= new Dependency();
localDependency27.SetId(transientGuid2);
localDependency27.Name = name;
transientDependency1 = localDependency27;
var localDependency33= new Dependency();
localDependency33.SetId(transientGuid2);
localDependency33.Name = name;
transientDependency1 = localDependency33;
return new Service(transientDependency1);
}
}
Expand Down
10 changes: 5 additions & 5 deletions readme/factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ 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 localIsFake28 = isFake;
if (localIsFake28)
bool localIsFake34 = isFake;
if (localIsFake34)
{
{transientIDependency1 = new FakeDependency();
goto transientIDependency1Finish; }
}
Dependency localDependency29 = new Dependency(transientDateTimeOffset3);
Dependency localDependency35 = new Dependency(transientDateTimeOffset3);
// And do something about it.
localDependency29.Initialize();
localDependency35.Initialize();
// And at the end return an instance
transientIDependency1 = localDependency29;
transientIDependency1 = localDependency35;
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 @@ -130,8 +130,8 @@ partial class Composition
}
}

Dependency localDependency33 = new Dependency(_root._singletonClock39!, transientInt323, transientInt324);
return localDependency33;
Dependency localDependency39 = new Dependency(_root._singletonClock39!, transientInt323, transientInt324);
return localDependency39;
};
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 @@ -61,8 +61,8 @@ partial class Composition
{
Func<IDependency> perBlockFunc1 = new Func<IDependency>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IDependency localValue34 = new Dependency();
return localValue34;
IDependency localValue40 = new Dependency();
return localValue40;
});
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 localValue32 = new Dependency();
return localValue32;
IDependency localValue38 = new Dependency();
return localValue38;
});
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 T: IDisposable
{
TaskFactory<IService<T, bool>> perBlockTaskFactory2;
CancellationToken localCancellationToken48 = cancellationToken;
CancellationToken localCancellationToken54 = cancellationToken;
TaskCreationOptions transientTaskCreationOptions3 = TaskCreationOptions.None;
TaskCreationOptions localTaskCreationOptions49 = transientTaskCreationOptions3;
TaskCreationOptions localTaskCreationOptions55 = transientTaskCreationOptions3;
TaskContinuationOptions transientTaskContinuationOptions4 = TaskContinuationOptions.None;
TaskContinuationOptions localTaskContinuationOptions50 = transientTaskContinuationOptions4;
TaskContinuationOptions localTaskContinuationOptions56 = transientTaskContinuationOptions4;
TaskScheduler transientTaskScheduler5 = TaskScheduler.Default;
TaskScheduler localTaskScheduler51 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService<T, bool>>(localCancellationToken48, localTaskCreationOptions49, localTaskContinuationOptions50, localTaskScheduler51);
TaskScheduler localTaskScheduler57 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService<T, bool>>(localCancellationToken54, localTaskCreationOptions55, localTaskContinuationOptions56, localTaskScheduler57);
Func<IService<T, bool>> perBlockFunc1 = new Func<IService<T, bool>>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
OtherService<T> transientOtherService6;
IDependency<T> localDependency53 = new Dependency<T>();
transientOtherService6 = new OtherService<T>(localDependency53);
IService<T, bool> localValue52 = transientOtherService6;
return localValue52;
IDependency<T> localDependency59 = new Dependency<T>();
transientOtherService6 = new OtherService<T>(localDependency59);
IService<T, bool> localValue58 = transientOtherService6;
return localValue58;
});
Task<IService<T, bool>> transientTask0;
// Injects an instance factory
Func<IService<T, bool>> localFactory54 = perBlockFunc1;
Func<IService<T, bool>> localFactory60 = perBlockFunc1;
// Injects a task factory creating and scheduling task objects
TaskFactory<IService<T, bool>> localTaskFactory55 = perBlockTaskFactory2;
TaskFactory<IService<T, bool>> localTaskFactory61 = perBlockTaskFactory2;
// Creates and starts a task using the instance factory
transientTask0 = localTaskFactory55.StartNew(localFactory54);
transientTask0 = localTaskFactory61.StartNew(localFactory60);
return transientTask0;
}

Expand All @@ -117,26 +117,26 @@ partial class Composition
where T1: struct
{
TaskFactory<IService<T, T1>> perBlockTaskFactory2;
CancellationToken localCancellationToken56 = cancellationToken;
CancellationToken localCancellationToken62 = cancellationToken;
TaskCreationOptions transientTaskCreationOptions3 = TaskCreationOptions.None;
TaskCreationOptions localTaskCreationOptions57 = transientTaskCreationOptions3;
TaskCreationOptions localTaskCreationOptions63 = transientTaskCreationOptions3;
TaskContinuationOptions transientTaskContinuationOptions4 = TaskContinuationOptions.None;
TaskContinuationOptions localTaskContinuationOptions58 = transientTaskContinuationOptions4;
TaskContinuationOptions localTaskContinuationOptions64 = transientTaskContinuationOptions4;
TaskScheduler transientTaskScheduler5 = TaskScheduler.Default;
TaskScheduler localTaskScheduler59 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService<T, T1>>(localCancellationToken56, localTaskCreationOptions57, localTaskContinuationOptions58, localTaskScheduler59);
TaskScheduler localTaskScheduler65 = transientTaskScheduler5;
perBlockTaskFactory2 = new TaskFactory<IService<T, T1>>(localCancellationToken62, localTaskCreationOptions63, localTaskContinuationOptions64, localTaskScheduler65);
Func<IService<T, T1>> perBlockFunc1 = new Func<IService<T, T1>>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IService<T, T1> localValue60 = new Service<T, T1>(new Dependency<T>());
return localValue60;
IService<T, T1> localValue66 = new Service<T, T1>(new Dependency<T>());
return localValue66;
});
Task<IService<T, T1>> transientTask0;
// Injects an instance factory
Func<IService<T, T1>> localFactory61 = perBlockFunc1;
Func<IService<T, T1>> localFactory67 = perBlockFunc1;
// Injects a task factory creating and scheduling task objects
TaskFactory<IService<T, T1>> localTaskFactory62 = perBlockTaskFactory2;
TaskFactory<IService<T, T1>> localTaskFactory68 = perBlockTaskFactory2;
// Creates and starts a task using the instance factory
transientTask0 = localTaskFactory62.StartNew(localFactory61);
transientTask0 = localTaskFactory68.StartNew(localFactory67);
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 T: IDisposable
{
OtherService<T> transientOtherService0;
IDependency<T> localDependency63 = new Dependency<T>();
transientOtherService0 = new OtherService<T>(localDependency63);
IDependency<T> localDependency69 = new Dependency<T>();
transientOtherService0 = new OtherService<T>(localDependency69);
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<T2> GetOtherService<T2>()
{
OtherService<T2> transientOtherService0;
IDependency<T2> localDependency64 = new Dependency<T2>();
transientOtherService0 = new OtherService<T2>(localDependency64);
IDependency<T2> localDependency70 = new Dependency<T2>();
transientOtherService0 = new OtherService<T2>(localDependency70);
return transientOtherService0;
}

Expand Down
8 changes: 4 additions & 4 deletions readme/lazy.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ partial class Composition
{
Func<IDependency> perBlockFunc2 = new Func<IDependency>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IDependency localValue35 = new Dependency();
return localValue35;
IDependency localValue41 = new Dependency();
return localValue41;
});
Lazy<IDependency> transientLazy1;
// Injects an instance factory
Func<IDependency> localFactory36 = perBlockFunc2;
Func<IDependency> localFactory42 = perBlockFunc2;
// Creates an instance that supports lazy initialization
transientLazy1 = new Lazy<IDependency>(localFactory36, true);
transientLazy1 = new Lazy<IDependency>(localFactory42, true);
return new Service(transientLazy1);
}
}
Expand Down
10 changes: 5 additions & 5 deletions readme/manually-started-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ partial class Composition
{
Func<IDependency> perBlockFunc2 = new Func<IDependency>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IDependency localValue37 = new Dependency();
return localValue37;
IDependency localValue43 = new Dependency();
return localValue43;
});
Task<IDependency> transientTask1;
Func<IDependency> localFactory38 = perBlockFunc2;
CancellationToken localCancellationToken39 = cancellationToken;
transientTask1 = new Task<IDependency>(localFactory38, localCancellationToken39);
Func<IDependency> localFactory44 = perBlockFunc2;
CancellationToken localCancellationToken45 = cancellationToken;
transientTask1 = new Task<IDependency>(localFactory44, localCancellationToken45);
return new Service(transientTask1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions readme/scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ partial class Composition: IDisposable
Func<Session> perBlockFunc1 = new Func<Session>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
Composition transientComposition3 = this;
Session localValue69 = new Session(transientComposition3);
return localValue69;
Session localValue75 = new Session(transientComposition3);
return localValue75;
});
return new Program(perBlockFunc1);
}
Expand Down
8 changes: 4 additions & 4 deletions readme/simplified-factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ partial class Composition
get
{
Dependency transientDependency1;
Dependency localDependency30 = new Dependency();
Dependency localDependency36 = new Dependency();
DateTimeOffset transientDateTimeOffset3 = DateTimeOffset.Now;
DateTimeOffset localTime31 = transientDateTimeOffset3;
localDependency30.Initialize(localTime31);
transientDependency1 = localDependency30;
DateTimeOffset localTime37 = transientDateTimeOffset3;
localDependency36.Initialize(localTime37);
transientDependency1 = localDependency36;
return new Service(transientDependency1);
}
}
Expand Down
20 changes: 10 additions & 10 deletions readme/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,26 @@ partial class Composition
public IService GetRoot(CancellationToken cancellationToken)
{
TaskFactory<IDependency> perBlockTaskFactory3;
CancellationToken localCancellationToken40 = cancellationToken;
CancellationToken localCancellationToken46 = cancellationToken;
TaskCreationOptions transientTaskCreationOptions4 = TaskCreationOptions.None;
TaskCreationOptions localTaskCreationOptions41 = transientTaskCreationOptions4;
TaskCreationOptions localTaskCreationOptions47 = transientTaskCreationOptions4;
TaskContinuationOptions transientTaskContinuationOptions5 = TaskContinuationOptions.None;
TaskContinuationOptions localTaskContinuationOptions42 = transientTaskContinuationOptions5;
TaskContinuationOptions localTaskContinuationOptions48 = transientTaskContinuationOptions5;
TaskScheduler transientTaskScheduler6 = TaskScheduler.Current;
TaskScheduler localTaskScheduler43 = transientTaskScheduler6;
perBlockTaskFactory3 = new TaskFactory<IDependency>(localCancellationToken40, localTaskCreationOptions41, localTaskContinuationOptions42, localTaskScheduler43);
TaskScheduler localTaskScheduler49 = transientTaskScheduler6;
perBlockTaskFactory3 = new TaskFactory<IDependency>(localCancellationToken46, localTaskCreationOptions47, localTaskContinuationOptions48, localTaskScheduler49);
Func<IDependency> perBlockFunc2 = new Func<IDependency>([MethodImpl(MethodImplOptions.AggressiveInlining)] () =>
{
IDependency localValue44 = new Dependency();
return localValue44;
IDependency localValue50 = new Dependency();
return localValue50;
});
Task<IDependency> transientTask1;
// Injects an instance factory
Func<IDependency> localFactory45 = perBlockFunc2;
Func<IDependency> localFactory51 = perBlockFunc2;
// Injects a task factory creating and scheduling task objects
TaskFactory<IDependency> localTaskFactory46 = perBlockTaskFactory3;
TaskFactory<IDependency> localTaskFactory52 = perBlockTaskFactory3;
// Creates and starts a task using the instance factory
transientTask1 = localTaskFactory46.StartNew(localFactory45);
transientTask1 = localTaskFactory52.StartNew(localFactory51);
return new Service(transientTask1);
}
}
Expand Down
Loading

0 comments on commit ffe65e7

Please sign in to comment.