Skip to content

Commit cebf487

Browse files
Add EF sample
1 parent 6b16d51 commit cebf487

20 files changed

Lines changed: 148 additions & 21 deletions

File tree

Pure.DI.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GrpcClient", "samples\GrpcC
122122
EndProject
123123
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "samples\ConsoleApp\ConsoleApp.csproj", "{006A6849-86DC-43C7-8297-67249A807439}"
124124
EndProject
125+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF", "samples\EF\EF.csproj", "{658990AA-FA40-4B28-8E14-2AB8BBD9C701}"
126+
EndProject
125127
Global
126128
GlobalSection(SolutionConfigurationPlatforms) = preSolution
127129
Debug|Any CPU = Debug|Any CPU
@@ -244,6 +246,10 @@ Global
244246
{006A6849-86DC-43C7-8297-67249A807439}.Debug|Any CPU.Build.0 = Debug|Any CPU
245247
{006A6849-86DC-43C7-8297-67249A807439}.Release|Any CPU.ActiveCfg = Release|Any CPU
246248
{006A6849-86DC-43C7-8297-67249A807439}.Release|Any CPU.Build.0 = Release|Any CPU
249+
{658990AA-FA40-4B28-8E14-2AB8BBD9C701}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
250+
{658990AA-FA40-4B28-8E14-2AB8BBD9C701}.Debug|Any CPU.Build.0 = Debug|Any CPU
251+
{658990AA-FA40-4B28-8E14-2AB8BBD9C701}.Release|Any CPU.ActiveCfg = Release|Any CPU
252+
{658990AA-FA40-4B28-8E14-2AB8BBD9C701}.Release|Any CPU.Build.0 = Release|Any CPU
247253
EndGlobalSection
248254
GlobalSection(NestedProjects) = preSolution
249255
{7C9E056B-CBA9-4548-9CDB-C5CE03C491B0} = {8163CDD7-7018-4301-A984-803C3807A6A6}
@@ -274,5 +280,6 @@ Global
274280
{29F9986B-4B32-4C30-AECA-D68EAB4EA9CB} = {FA80D231-C641-4A49-99C6-0C065D818B07}
275281
{B0E4907A-2BB2-44B4-9BB6-70E1518BEE5C} = {FA80D231-C641-4A49-99C6-0C065D818B07}
276282
{006A6849-86DC-43C7-8297-67249A807439} = {FA80D231-C641-4A49-99C6-0C065D818B07}
283+
{658990AA-FA40-4B28-8E14-2AB8BBD9C701} = {FA80D231-C641-4A49-99C6-0C065D818B07}
277284
EndGlobalSection
278285
EndGlobal

samples/AvaloniaApp/AvaloniaApp.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
<ProjectReference Include="..\..\src\Pure.DI.Core\Pure.DI.Core.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
1414
<ProjectReference Include="..\..\src\Pure.DI\Pure.DI.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
1515
<ProjectReference Include="..\Clock\Clock.csproj"/>
16-
<PackageReference Include="Avalonia" Version="11.3.3" />
17-
<PackageReference Include="Avalonia.Desktop" Version="11.3.3" />
18-
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.3" />
19-
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.3" />
16+
<PackageReference Include="Avalonia" Version="11.3.4" />
17+
<PackageReference Include="Avalonia.Desktop" Version="11.3.4" />
18+
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.4" />
19+
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.4" />
2020
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
21-
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.3" />
21+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.4" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

samples/AvaloniaSimpleApp/AvaloniaSimpleApp.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<ItemGroup>
1111
<ProjectReference Include="..\..\src\Pure.DI.Core\Pure.DI.Core.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
1212
<ProjectReference Include="..\..\src\Pure.DI\Pure.DI.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
13-
<PackageReference Include="Avalonia" Version="11.3.3" />
14-
<PackageReference Include="Avalonia.Desktop" Version="11.3.3" />
15-
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.3" />
16-
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.3" />
13+
<PackageReference Include="Avalonia" Version="11.3.4" />
14+
<PackageReference Include="Avalonia.Desktop" Version="11.3.4" />
15+
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.4" />
16+
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.4" />
1717
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
18-
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.3" />
18+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.4" />
1919
</ItemGroup>
2020
</Project>

samples/Clock.Tests/Clock.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Moq" Version="4.20.72"/>
1111
<PackageReference Include="Shouldly" Version="4.3.0"/>
1212
<PackageReference Include="xunit" Version="2.9.3"/>
13-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
13+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>

samples/EF/Composition.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace EF;
2+
3+
partial class Composition: ServiceProviderFactory<Composition>
4+
{
5+
[Conditional("DI")]
6+
private void Setup() => DI.Setup()
7+
.DependsOn(Base)
8+
9+
.Root<Program>(nameof(Root))
10+
11+
.Bind().As(Singleton).To<IdGenerator>()
12+
.Bind<int>(Autoincrement).To(ctx => {
13+
ctx.Inject(out IIdGenerator idGenerator);
14+
return idGenerator.Generate(ctx.ConsumerTypes[0]);
15+
})
16+
.Bind().To<Dependency>();
17+
}

samples/EF/Dependency.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace EF;
2+
3+
class Dependency : IDependency
4+
{
5+
public string ConvertToString(Person person) =>
6+
$"Id: {person.Id:0000}, Name: \"{person.Name}\"";
7+
}

samples/EF/EF.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>$(targetFrameworkVersion)</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\Pure.DI.Core\Pure.DI.Core.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
10+
<ProjectReference Include="..\..\src\Pure.DI\Pure.DI.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
11+
<Compile Include="..\..\src\Pure.DI.MS\any\Pure.DI\MS\*.cs" Link=""/>
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.8" />
13+
</ItemGroup>
14+
15+
</Project>

samples/EF/GlobalUsings.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Global using directives
2+
global using System.ComponentModel.DataAnnotations;
3+
global using System.ComponentModel.DataAnnotations.Schema;
4+
global using System.Diagnostics;
5+
global using EF;
6+
global using Microsoft.EntityFrameworkCore;
7+
global using Microsoft.Extensions.DependencyInjection;
8+
global using Pure.DI;
9+
global using Pure.DI.MS;
10+
global using static Pure.DI.Lifetime;
11+
global using static Pure.DI.Tag;

samples/EF/IDependency.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace EF;
2+
3+
interface IDependency
4+
{
5+
string ConvertToString(Person person);
6+
}

samples/EF/IIdGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace EF;
2+
3+
interface IIdGenerator
4+
{
5+
int Generate(Type type);
6+
}

0 commit comments

Comments
 (0)