Created
September 12, 2012 19:54
-
-
Save akimboyko/3709454 to your computer and use it in GitHub Desktop.
Ninject Kernel with multiple Modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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