Created
March 28, 2018 15:19
-
-
Save Alexei000/2fc303c5412f579304643815fc5ab8c3 to your computer and use it in GitHub Desktop.
Register custom services
This file contains 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
protected void RegisterCustomServicesForServiceTesting() | |
{ | |
// IRepository<T> should be solved using InMemoryRepository<T>, by default | |
Kernel.Rebind(typeof(IRepository<>)).To(typeof(InMemoryRepository<>)); | |
// IRepository<T> must be solved to Repository<T>, if used in CachedRepository<T> | |
Kernel.Rebind(typeof(IRepository<>)).To(typeof(InMemoryRepository<>)).WhenInjectedInto(typeof(CachedRepository<>)); | |
var nonCachedTypes = NinjectCommon.GetNonCachedTypes(); | |
nonCachedTypes.ForEach(type => | |
{ | |
Type memoryRepositoryType = typeof(InMemoryRepository<>).MakeGenericType(type); | |
var repoType = typeof(IRepository<>).MakeGenericType(type); | |
// allow access as normal repository | |
Kernel.Rebind(repoType).To(memoryRepositoryType); | |
}); | |
Kernel.Rebind<IScopedDataAccess>().To<ScopedDataAccess>().InSingletonScope(); | |
Kernel.Rebind<ILoggingService>().To<InMemoryLoggingService>().InSingletonScope(); | |
Logger = Kernel.Get<ILoggingService>() as InMemoryLoggingService; | |
var mockConfig = Substitute.For<IConfigService>(); | |
Kernel.Rebind<IConfigService>().ToConstant(mockConfig).InSingletonScope(); | |
Kernel.Rebind<IEnvironmentProxyService>().To<EnvironmentProxyServiceMock>(); | |
Kernel.Rebind<IEnvironmentDatabaseProxyService>().To<EnvironmentDatabaseProxyServiceMock>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment