I'm successfully using Ninject in my web applications by deriving my Global from NinjectHttpApplication and using the NinjectHttpModule in my web.config
What I want to do now is us DI in one of my class libraries and I don't know how to go about this. I have the following dummy class:
/// <summary>
/// Testing Ninject DI in a class library
/// </summary>
public class Class1
{
[Inject]
ICustomerRepository CustomerRepository { get; set; }
public string SomeText { get; set; }
public Class1(string text)
{
MyConfig config = new MyConfig();
config.Configure();
SomeText = text;
}
public Customer GetCustomer()
{
var customer = CustomerRepository.GetCustomer();
return customer;
}
}
public class MyConfig
{
public IKernel Configure()
{
IKernel kernel = new StandardKernel(new NinjectRepositoryModule());
return kernel;
}
}
When I instantiate Class1 and call GetCustomer(), the CustomerRepository is null, so I'm obviously doing something wrong?
Also, if I wanted to use constructor injection and have my constructor like
public Class1([Inject] ICustomerRepository repository)
how would I go about instantiating Class1?
Quite new to Ninject, so this could all be very easy stuff.