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

边栏推荐
- C scanf函数
- Machine learning learning notes
- C secret arts script Chapter 2 (detailed explanation of pointers) (Section 3)
- Jenkins' RPC test project
- 【OCR】AspriseOCR C# 英文、數字識別(中文不行)
- Use Baidu AIP to obtain the text in the specified area of the screen
- 你敢信?开发一个管理系统我只用了两天
- SQL cross database injection
- Two months' experience in C language
- win10_ Home Edition cannot use remote desktop, and can be accessed by remote desktop.
猜你喜欢

Visual positioning guidance system for industrial manipulator (robot)

Can you believe it? It took me only two days to develop a management system

Ankai microelectronics rushes to the scientific innovation board: the annual revenue of 500million Xiaomi industry fund is the shareholder

selenium之元素定位

Data collection

JS (II) syntaxerror: cannot use import statement outside a module

JUnit test suite method sorting (method 2 is not easy to use)
![[wechat applet] 2 Environmental preparation](/img/8d/7bb68ca7d10751a6e992a53c5eff4a.jpg)
[wechat applet] 2 Environmental preparation

Huawei equipment configuration BGP as number replacement

数据的收集
随机推荐
安凯微电子冲刺科创板:年营收5亿 小米产业基金是股东
QT database realizes page turning function
Module yaml error: Unexpected key in data: static_context [line 9 col 3]
Mysql之索引和视图
Webdriver opens in full screen and a prompt "Chrome is under the control of automatic test software" appears in Chrome
QT to realize the simple use of SQLite database
[wp][入门]攻防世界-game
Machine learning learning notes
NetCore结合CAP事件总线实现分布式事务——消息(2)
C scanf函数
win10_ Home Edition cannot use remote desktop, and can be accessed by remote desktop.
Location (I) error: command erred out with exit status
PMP敏捷知识点
MySQL index and view
Configuring OSPF pseudo connection for Huawei devices
C secret arts script Chapter 5 (paragraph) (Section 3)
Variable parameters
QT multi thread drawing and real-time refreshing method
函数递归示例
C secret script Chapter 3 (detailed explanation of string function) (Section 1)