changed to .NET5 , + Property injection

This commit is contained in:
2020-11-29 21:15:45 +01:00
parent 5ca347fc6a
commit e2027a5f7e
6 changed files with 59 additions and 6 deletions

View File

@ -3,11 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126 VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoFacSamles", "AutoFacSamles\AutoFacSamles.csproj", "{2CFA4809-16F7-4DB9-B4BB-CF60945656E5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AutoFacSamles", "AutoFacSamles\AutoFacSamles.csproj", "{2CFA4809-16F7-4DB9-B4BB-CF60945656E5}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatternDemoCore", "PatternDemoCore\PatternDemoCore.csproj", "{D8041EF1-F2AC-4A04-A7A5-56E2CB6F249C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PatternDemoCore", "PatternDemoCore\PatternDemoCore.csproj", "{D8041EF1-F2AC-4A04-A7A5-56E2CB6F249C}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatternDemoCore2", "PatternDemo2\PatternDemoCore2.csproj", "{2152A909-E97C-453A-8A6C-869F7987D7B5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PatternDemoCore2", "PatternDemo2\PatternDemoCore2.csproj", "{2152A909-E97C-453A-8A6C-869F7987D7B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoFacSamples2", "AutoFacSamples2\AutoFacSamples2.csproj", "{0EB88BA8-3B88-4142-A6D3-07F72120488D}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +29,10 @@ Global
{2152A909-E97C-453A-8A6C-869F7987D7B5}.Debug|Any CPU.Build.0 = Debug|Any CPU {2152A909-E97C-453A-8A6C-869F7987D7B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2152A909-E97C-453A-8A6C-869F7987D7B5}.Release|Any CPU.ActiveCfg = Release|Any CPU {2152A909-E97C-453A-8A6C-869F7987D7B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2152A909-E97C-453A-8A6C-869F7987D7B5}.Release|Any CPU.Build.0 = Release|Any CPU {2152A909-E97C-453A-8A6C-869F7987D7B5}.Release|Any CPU.Build.0 = Release|Any CPU
{0EB88BA8-3B88-4142-A6D3-07F72120488D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0EB88BA8-3B88-4142-A6D3-07F72120488D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0EB88BA8-3B88-4142-A6D3-07F72120488D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0EB88BA8-3B88-4142-A6D3-07F72120488D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="6.0.0" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,35 @@
using Autofac;
using System;
namespace AutoFacSamples2
{
public class Parent
{
public override string ToString()
{
return "I am your father";
}
}
public class Child
{
public string Name { get; set; }
public Parent Parent { get; set; }
}
internal class Program
{
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterType<Parent>();
builder.RegisterType<Child>().PropertiesAutowired();
var container = builder.Build();
var parent = container.Resolve<Child>().Parent;
Console.WriteLine(parent);
}
}
}

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>