当前位置:网站首页>Autofac Beginner (1)
Autofac Beginner (1)
2022-06-12 14:46:00 【There are poems and distant places】
Autofac
One 、 Create a console project
introduce nuget package
Two 、 Create an interface
using System;
using System.Collections.Generic;
using System.Text;
namespace _02_autofac
{
internal interface Person
{
void Eat();
void Say();
}
}
3、 ... and 、 Create implementation classes
using System;
using System.Collections.Generic;
using System.Text;
namespace _02_autofac
{
public class Student:Person
{
public void Eat()
{
Console.WriteLine(" have breakfast ");
}
public void Say()
{
Console.WriteLine(" Say good morning ");
}
}
}
Four 、 Create examples
using Autofac;
using System;
using System.ComponentModel;
namespace _02_autofac
{
internal class Program
{
private static Autofac.IContainer Container {
get; set; }
static void Main(string[] args)
{
// Create a container
var builder = new ContainerBuilder();
// establish builder, And in builder Registration type in .
builder.RegisterType<Student>().As<Person>();
// Instantiate container ( You can say the first step is to merge )
Container = builder.Build();
// Where you need to use interfaces , adopt container To parse an instance of an excuse .
Person person = Container.Resolve<Person>();
person.Eat();
person.Say();
}
}
}
5、 ... and 、 test result

边栏推荐
- Sorting out the differences between ABS () and Fabs () in C language
- Common DOS commands
- 安凯微电子冲刺科创板:年营收5亿 小米产业基金是股东
- 野指针理解
- Detailed explanation of factory pattern (simple factory pattern, factory method pattern, abstract factory pattern) Scala code demonstration
- Two months' experience in C language
- The difference between parameter and argument in C language
- Ankai microelectronics rushes to the scientific innovation board: the annual revenue of 500million Xiaomi industry fund is the shareholder
- 【OCR】AspriseOCR C# 英文、数字识别(中文不行)
- tc菜单分割
猜你喜欢
![[wechat applet] 5 Applet structure directory](/img/d6/4796c8b8fe482b261c5a1fbf79ba2b.jpg)
[wechat applet] 5 Applet structure directory

三维重建系统 | L3双视角运动恢复结构(SFM双目SFM)

Location (I) error: command erred out with exit status

webdriver入门

Data collection
![[wechat applet] 1 Introduction to wechat applet](/img/7c/6e62269438a0dd7e7172cb37af9fb9.jpg)
[wechat applet] 1 Introduction to wechat applet
![[wechat applet] 3 The first wechat applet](/img/40/1571c11363e72f5a1e932586a1f240.jpg)
[wechat applet] 3 The first wechat applet

Visual positioning guidance system for industrial manipulator (robot)

Energy chain smart electronics landed on NASDAQ: Bain is the shareholder to become the first share of charging services in China

PMP敏捷知识点
随机推荐
MySQL index and view
Common DOS commands
SQL cross database injection
野指针理解
MobileOne: 移动端仅需1ms的高性能骨干,你值得拥有!
Junit异常情况,断言异常信息不为空过的方法
交换数字,异或求单,操作符相关
Crawler problem set (I) record
华为设备配置H虚拟专用网
C scanf函数
JUnit test suite method sorting (method 2 is not easy to use)
jenkins的RPC测试项目
[lambda operation jcf]
C secret arts script Chapter 5 (structure) (Section 1)
tc菜单分割
Two months' experience in C language
The igatewayloadbalancer interface implements routing. Otherwise, it follows Sid routing
Nesting of C language annotations
启明智显分享| 2.8寸手持中控屏应用方案
数据的收集