当前位置:网站首页>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

边栏推荐
- 华为设备配置OSPF伪连接
- QT multi thread drawing and real-time refreshing method
- NETCORE combined with cap event bus to realize distributed transaction - message (2)
- 模块八
- Chapter I exercises of program construction and interpretation
- Ali suggests that all POJO attributes use wrapper classes, but have you noticed these pits?
- Array one
- 用游戏来讲序列化与反序列化机制
- 能链智电登陆纳斯达克:贝恩是股东 成中国充电服务第一股
- 新技术:高效的自监督视觉预训练,局部遮挡再也不用担心!
猜你喜欢

掌门教育被强制退市:上市仅一年时间 软银CMC损失惨重

【LDA】EM变分推理 粗略版笔记【待完善

Ali suggests that all POJO attributes use wrapper classes, but have you noticed these pits?

MobileOne: 移动端仅需1ms的高性能骨干,你值得拥有!

Interview (XI) futu written test questions

Easygui query the company name in the document

我愿称之为史上最全的深度学习面经总结(附答案详解)

Can you believe it? It took me only two days to develop a management system
![[wp][入门]攻防世界-game](/img/07/1ea54d14ba3caca25a68786d5be4a6.png)
[wp][入门]攻防世界-game

Huawei equipment is configured with H virtual private network
随机推荐
Interview (XI) futu written test questions
Huawei equipment is configured with H virtual private network
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
ShardingSphere实践(6)——弹性伸缩
NETCORE combined with cap event bus to realize distributed transaction - message (2)
Common assertions in JUnit testing
程序构造和解释之第一章习题
Huawei equipment configuration BGP as number replacement
Basic usage of scanner
Ankai microelectronics rushes to the scientific innovation board: the annual revenue of 500million Xiaomi industry fund is the shareholder
Tensorrt based in-depth learning model deployment practice tutorial!
Autofac初学(1)
C secret arts script Chapter 2 (detailed explanation of pointer) (Section 1)
C 字符串
C secret arts script Chapter 2 (detailed explanation of pointers) (Section 3)
[lambda operation jcf]
模块八
C magic skill Chapter 4 (detailed explanation of memory function)
NetCore结合CAP事件总线实现分布式事务——入门(1)
Tu oses le croire? Il m'a fallu deux jours pour développer un système de gestion.