Skip to content

Commit 22b8da7

Browse files
Add EF sample
1 parent 6b16d51 commit 22b8da7

18 files changed

Lines changed: 181 additions & 33 deletions

File tree

.run/EF.run.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="EF" type="DotNetProject" factoryName=".NET Project" folderName="Examples">
3+
<option name="EXE_PATH" value="$PROJECT_DIR$/samples/EF/bin/Debug/net9.0/EF.exe" />
4+
<option name="PROGRAM_PARAMETERS" value="" />
5+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/samples/EF/bin/Debug/net9.0" />
6+
<option name="PASS_PARENT_ENVS" value="1" />
7+
<option name="USE_EXTERNAL_CONSOLE" value="0" />
8+
<option name="ENV_FILE_PATHS" value="" />
9+
<option name="REDIRECT_INPUT_PATH" value="" />
10+
<option name="PTY_MODE" value="Auto" />
11+
<option name="MIXED_MODE_DEBUG" value="0" />
12+
<option name="USE_MONO" value="0" />
13+
<option name="RUNTIME_ARGUMENTS" value="" />
14+
<option name="AUTO_ATTACH_CHILDREN" value="0" />
15+
<option name="PROJECT_PATH" value="$PROJECT_DIR$/samples/EF/EF.csproj" />
16+
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
17+
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
18+
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
19+
<option name="PROJECT_KIND" value="DotNetCore" />
20+
<option name="PROJECT_TFM" value="net9.0" />
21+
<method v="2">
22+
<option name="Build" />
23+
</method>
24+
</configuration>
25+
</component>

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace EF;
2+
3+
using System.Diagnostics;
4+
using Pure.DI;
5+
using Pure.DI.MS;
6+
7+
partial class Composition: ServiceProviderFactory<Composition>
8+
{
9+
[Conditional("DI")]
10+
private void Setup() => DI.Setup()
11+
.DependsOn(Base)
12+
.Root<Program>(nameof(Root))
13+
.Bind().To<Dependency>();
14+
}

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/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/Person.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace EF;
2+
3+
using System.ComponentModel.DataAnnotations;
4+
using System.ComponentModel.DataAnnotations.Schema;
5+
6+
record Person
7+
{
8+
[Key]
9+
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
10+
public int Id { get; private set; }
11+
12+
[StringLength(16)]
13+
public string Name { get; init; } = "";
14+
15+
[NotMapped]
16+
public required IDependency Dependency { get; init; }
17+
18+
public override string ToString() => Dependency.ConvertToString(this);
19+
}

0 commit comments

Comments
 (0)