Skip to content

Instantly share code, notes, and snippets.

@SirRufo
Created July 21, 2017 09:17
Show Gist options
  • Save SirRufo/1899f804c8441167afe6ec4b6de65738 to your computer and use it in GitHub Desktop.
Save SirRufo/1899f804c8441167afe6ec4b6de65738 to your computer and use it in GitHub Desktop.
MVCE for so45220678
using Castle.Windsor;
using System;
namespace SimpleWindsorTest
{
class Program
{
static void Main(string[] args)
{
var container = new WindsorContainer();
container.Register(Castle.MicroKernel.Registration.Component.For<IPersonRepository>().ImplementedBy<PersonRepository>());
container.Register(Castle.MicroKernel.Registration.Component.For<IUnitOfWork>().ImplementedBy<UnitOfWork>());
var rep = container.Resolve<IPersonRepository>();
container.Register(Castle.MicroKernel.Registration.Component.For<IPersonService>().ImplementedBy<PersonService>());
var svc = container.Resolve<IPersonService>();
}
}
#region interface declaration
public interface IUnitOfWork
{
}
public interface IPersonRepository
{
}
public interface IPersonService
{
}
#endregion
#region class declaration
public class UnitOfWork : IUnitOfWork
{
}
public class PersonRepository : IPersonRepository
{
readonly IUnitOfWork _unitOfWork;
public PersonRepository(IUnitOfWork unitOfWork)
{
if (unitOfWork == null) throw new ArgumentNullException(nameof(unitOfWork));
_unitOfWork = unitOfWork;
}
}
public class PersonService : IPersonService
{
readonly IPersonRepository _personRepository;
readonly IUnitOfWork _unitOfWork;
public PersonService(IPersonRepository personRepository, IUnitOfWork unitOfWork)
{
if (personRepository == null) throw new ArgumentNullException(nameof(personRepository));
if (unitOfWork == null) throw new ArgumentNullException(nameof(unitOfWork));
_personRepository = personRepository;
_unitOfWork = unitOfWork;
}
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment