I'm interested how to implement my constructor in services. I'm a bit new to .NET so don't get me wrong if question is too trivial.
This are my current constructors but I would like to fully understand (since it looks like its working, I took code from somewhere)
// initialize UnitOfWork
private IUnitOfWork _unitOfWork;
public TownService()
: this(new UnitOfWork())
{
}
public TownService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
What does : this
means and which one is called first? Also I saw there is constructor with : base
but I think thats the one thats calling superclass
first.
Do I need to call new UnitOfWork()
? Isn't UnitOfWork
supposed to be factory
(shared) instance? Or it is factory
and new UnitOfWork
is not creating new but taking initialized one from memory?
Thanks.