mirror of
https://github.com/Stone-Red-Code/DynamicInjector.git
synced 2026-09-04 09:06:06 +02:00
Add project files.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>DynamicInjector_Test</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DynamicInjector\DynamicInjector.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace DynamicInjector_Test;
|
||||
|
||||
internal class FirstTestService : IFirstTestService
|
||||
{
|
||||
private int count = 0;
|
||||
|
||||
public void Print()
|
||||
{
|
||||
Console.WriteLine(nameof(FirstTestService) + " | " + count++);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace DynamicInjector_Test;
|
||||
|
||||
internal interface IFirstTestService
|
||||
{
|
||||
public void Print();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using DynamicInjector;
|
||||
|
||||
namespace DynamicInjector_Test;
|
||||
|
||||
internal class Prgramm
|
||||
{
|
||||
private static void Main()
|
||||
{
|
||||
InjectionContainer injector = new InjectionContainer();
|
||||
injector.RegisterGlobal<IFirstTestService, FirstTestService>();
|
||||
injector.RegisterLocal<SecondTestService>();
|
||||
|
||||
TestClass? testClass = injector.Resolve<TestClass>();
|
||||
|
||||
testClass.Test();
|
||||
|
||||
injector.Invoke<TestClass>(testClass, (c) => c.Test);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace DynamicInjector_Test;
|
||||
|
||||
internal class SecondTestService
|
||||
{
|
||||
private readonly IFirstTestService firstTestService;
|
||||
private int count = 0;
|
||||
|
||||
public SecondTestService(IFirstTestService firstTestService)
|
||||
{
|
||||
this.firstTestService = firstTestService;
|
||||
}
|
||||
|
||||
public void Output()
|
||||
{
|
||||
firstTestService.Print();
|
||||
Console.WriteLine(nameof(SecondTestService) + " | " + count++);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using DynamicInjector;
|
||||
|
||||
namespace DynamicInjector_Test;
|
||||
|
||||
internal class TestClass
|
||||
{
|
||||
private readonly IFirstTestService testService;
|
||||
|
||||
[Inject]
|
||||
private SecondTestService? SecondTestService { get; set; }
|
||||
|
||||
public TestClass(IFirstTestService yes)
|
||||
{
|
||||
testService = yes;
|
||||
}
|
||||
|
||||
public void Test()
|
||||
{
|
||||
testService.Print();
|
||||
SecondTestService?.Output();
|
||||
}
|
||||
|
||||
public int SecondTest(SecondTestService secondTestService)
|
||||
{
|
||||
secondTestService.Output();
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user