mirror of
https://github.com/Stone-Red-Code/DynamicInjector.git
synced 2026-09-04 00:56:04 +02:00
- Add Scopes
This commit is contained in:
@@ -6,14 +6,29 @@ internal class Prgramm
|
||||
{
|
||||
private static void Main()
|
||||
{
|
||||
InjectionContainer injector = new InjectionContainer();
|
||||
injector.RegisterGlobal<IFirstTestService, FirstTestService>();
|
||||
injector.RegisterLocal<SecondTestService>();
|
||||
InjectionContainer container = new InjectionContainer();
|
||||
container.RegisterScoped<IFirstTestService, FirstTestService>();
|
||||
container.RegisterLocal<SecondTestService>();
|
||||
|
||||
TestClass? testClass = injector.Resolve<TestClass>();
|
||||
using (LifetimeScope scope = container.BeginScope())
|
||||
{
|
||||
TestClass? testClass = scope.Resolve<TestClass>();
|
||||
testClass.Test();
|
||||
int res = scope.Invoke<TestClass, int, SecondTestService>(testClass, (i) => i.SecondTest);
|
||||
|
||||
testClass.Test();
|
||||
Console.WriteLine(res);
|
||||
scope.Invoke<TestClass>(testClass, (i) => i.SecondTest);
|
||||
scope.Invoke<TestClass>(testClass, (i) => i.SecondTest);
|
||||
}
|
||||
|
||||
injector.Invoke<TestClass>(testClass, (c) => c.Test);
|
||||
Console.WriteLine();
|
||||
|
||||
using (LifetimeScope scope = container.BeginScope())
|
||||
{
|
||||
scope.Resolve<TestClass>().Test();
|
||||
scope.Resolve<TestClass>().Test();
|
||||
scope.Resolve<TestClass>().Test();
|
||||
scope.Resolve<TestClass>().Test();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ internal class TestClass
|
||||
|
||||
public void Test()
|
||||
{
|
||||
testService.Print();
|
||||
SecondTestService?.Output();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user