vendredi 20 février 2015

Always Valid Entity and Constructor Injection

Giving the following sample:



class Customer
{
ICustomerRepository repository;

private string name;

public Customer(string name, ICustomerRepository repository)
{
Name = name;
this.repository= repository;
}

public string Name
{
get {return name;}
set
{
if(String.IsNullOrWhiteSpace(value))
throw new ArgumentException();

name = value;
}
}
}



  • I'm using ninject IoC.

  • I abstract ninject container in an IFactory interface that has Get<>() method, so i want use only constructor injection. I do that because i don't want use [Inject] attributes.

  • I want follow the always valid entity principle.


In this scenario i can't do that because i have a parameter on constructor. There is an another approach to do that?


Aucun commentaire:

Enregistrer un commentaire