Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Created September 12, 2012 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akimboyko/3709454 to your computer and use it in GitHub Desktop.
Save akimboyko/3709454 to your computer and use it in GitHub Desktop.
Ninject Kernel with multiple Modules
void Main()
{
var kernel = new Ninject.StandardKernel(new EntitieseModule(), new DocumentStoreModule(), new ModelRepositoryModule());
}
public interface IModelRepository<T> where T: IModel
{
//interface stuff here
}
public interface IDocumentStore
{
}
public class DocumentStore : IDocumentStore
{
}
public interface IModel
{
}
public class User : IModel
{
}
public class UserRepository : IModelRepository<User>
{
public UserRepository(IDocumentStore documentStore, string databaseName)
{
//constructor code here
}
}
public class ModelRepositoryModule : NinjectModule
{
public override void Load()
{
string databaseName = "SomeName";
Bind<IModelRepository<User>>()
.To<UserRepository>()
.WithConstructorArgument("documentStore", Kernel.Get<IDocumentStore>())
.WithConstructorArgument("databaseName", databaseName);
}
}
public class DocumentStoreModule : NinjectModule
{
public override void Load()
{
Bind<IDocumentStore>()
.To<DocumentStore>();
}
}
public class EntitieseModule : NinjectModule
{
public override void Load()
{
Bind<User>()
.ToSelf();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment