Wrong use of IContainer
This commit is contained in:
12
PatternDemo2/PatternDemoCore2.csproj
Normal file
12
PatternDemo2/PatternDemoCore2.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
46
PatternDemo2/Program.cs
Normal file
46
PatternDemo2/Program.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Autofac;
|
||||
using System;
|
||||
|
||||
namespace PatternDemoCore
|
||||
{
|
||||
|
||||
public class Entity
|
||||
{
|
||||
private static Random random = new Random();
|
||||
private int number;
|
||||
|
||||
public Entity()
|
||||
{
|
||||
number = random.Next();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"test {number}";
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewModel
|
||||
{
|
||||
private readonly IContainer container;
|
||||
|
||||
public ViewModel(IContainer container)
|
||||
{
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public void Method()
|
||||
{
|
||||
var entity = container.Resolve<Entity>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Demo
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user