Ok, I feel like a total idiot. I have read the docs and still cant get this working with Ninject.
public class ContextAdapter:IDbSetProvider
{
private readonly IContextFactory _contextFactory;
#region Implementation of IDbSetProvider
public ContextAdapter(IContextFactory contextFactory)
{
this._contextFactory = contextFactory;
}
public IDbSet<TEntity> CreateDBSet<TEntity>() where TEntity : class
{
var context = _contextFactory.Create();
return context.Set<TEntity>();
}
#endregion
}
As you can see I am need to inject the contructor for the class above. Well, it is not going so well.
Help!! before I go back to writing perl code. Kidding!! LOl
Thoughts folks?
Your class
ContextAdapterdoes not implementIContextFactory. Do you have a class likeclass Factory : IContextFactory? That is what you are missing here. Then you can bind itkernel.Bind<IContextFactory>.To<Factory>()and Ninject will create that type for you when you request an object or when it needs to fulfill a contract. I think your confusion comes from the binding syntax. You are, in general, not binding parameters together, you are binding interfaces to concrete implementations. Here is a quick example:When you ask Ninject for
ICar, it will fulfill it with what was bound,Sedan.Sedanrequires anIEnginein its constructor, which Ninject will fulfill withGasEnginesince that is what was bound.