0
C# 및 생성자 종속성 주입에서 처음 두 생성자의 차이점은 무엇입니까? 특히 첫 번째 생성자의 :this
은 무엇을 의미합니까? 두 번째 생성자 또는 다른 것에 대한 축약입니까?C# - 객체 지향 프로그래밍 팩토리 메서드 생성자
private readonly IRepositoryOne _repositoryOne;
private readonly IRepositoryTwo _repositoryTwo;
private readonly IService _service;
private readonly ApplicationDbContext _context;
public MyContructor()
: this(new RepositoryOne(new ApplicationDbContext()),
new RepositoryTwo(new ApplicationDbContext())
new Service())
{
}
public MyContructor()
{
_context = new ApplicationDbContext();
_repositoryOne = new RepositoryOne(_context);
_repositoryTwo = new RepositoryTwo(_context);
_service = new Service();
}
public MyContructor(IRepositoryOne repositoryOne,
IRepositoryTwo repositoryTwo,
IService service)
{
_repositoryOne = repositoryOne;
_repositoryTwo = repositoryTwo;
_service = service;
}
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-constructors –
같은 시나리오에서 사용된다 https://stackoverflow.com/questions/1814953/c-sharp-constructor-chaining-how-to-do-it – Nkosi
@ L.Guthardt 첫 번째 호출은 세 번째 호출입니다. – Nkosi