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?
Edit:
- 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.
Abstraction of my the container:
interface IFactory
{
T Get<T>();
IEnumerable<T> GetAll<T>();
}
Implementation:
class ApplicationFactory : IFactory
{
private readonly IKernel ninjectKernel = ApplicationNinjectKernel.BuildNew();
public T Get<T>()
{
return ninjectKernel.Get<T>();
}
public IEnumerable<T> GetAll<T>()
{
return ninjectKernel.GetAll<T>();
}
}
ApplicationNinjectKernel.BuildNew() creates and return a new StandarKernel() with the binds..
ConstructorArgument sounds bad to me. With this approach i will put some ugly thing on my code and also will miss type checking at project time. :/