public void RegisterDependencies(Container container) { //http context container.RegisterInstance <HttpContextBase>(new HttpContextWrapper(HttpContext.Current) as HttpContextBase, new SingletonReuse()); //cache provider container.Register <ICacheProvider, HttpCacheProvider>(reuse: Reuse.Singleton); // settings register for access across app container.Register <IDatabaseSettings>(made: Made.Of(() => new DatabaseSettings()), reuse: Reuse.Singleton); //data provider : TODO: Use settings to determine the support for other providers container.Register <IDatabaseProvider>(made: Made.Of(() => new SqlServerDatabaseProvider()), reuse: Reuse.Singleton); //database context container.Register <IDatabaseContext>(made: Made.Of(() => DatabaseContextManager.GetDatabaseContext()), reuse: Reuse.Singleton); //and respositories container.Register(typeof(IDataRepository <>), typeof(EntityRepository <>)); var asm = AssemblyLoader.LoadBinDirectoryAssemblies(); //services //to register services, we need to get all types from services assembly and register each of them; var serviceAssembly = asm.First(x => x.FullName.Contains("mobSocial.Services")); var serviceTypes = serviceAssembly.GetTypes(). Where(type => type.IsPublic && // get public types !type.IsAbstract && // which are not interfaces nor abstract type.GetInterfaces().Length != 0); // which implementing some interface(s) container.RegisterMany(serviceTypes, reuse: Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Replace); //we need a trasient reporter service rather than singleton container.Register <IVerboseReporterService, VerboseReporterService>(reuse: Reuse.InResolutionScope, ifAlreadyRegistered: IfAlreadyRegistered.Replace); //settings var allSettingTypes = TypeFinder.ClassesOfType <ISettingGroup>(); foreach (var settingType in allSettingTypes) { var type = settingType; container.RegisterDelegate(type, resolver => { var instance = (ISettingGroup)Activator.CreateInstance(type); resolver.Resolve <ISettingService>().LoadSettings(instance); return(instance); }, reuse: Reuse.Singleton); } //and ofcourse the page generator container.Register <IPageGenerator, PageGenerator>(reuse: Reuse.Singleton); //event publishers and consumers container.Register <IEventPublisherService, EventPublisherService>(reuse: Reuse.Singleton); //all consumers which are not interfaces container.RegisterMany(new[] { typeof(IEventConsumer <>) }, serviceTypeCondition: type => !type.IsInterface); }
public OAuthDbContext Create() { try { return(DatabaseContextManager.GetDatabaseContext <OAuthDbContext>()); } catch { return(DatabaseContextManager.GetDatabaseContext <OAuthDbContext>(DatabaseManager.FallbackConnectionStringName)); } }
public void RegisterDependencies(Container container) { container.Register <IClientService, ClientService>(); container.Register <IAppTokenService, AppTokenService>(); container.RegisterDelegate <IDataRepository <OAuthClient> >( resolver => new EntityRepository <OAuthClient>(DatabaseContextManager.GetDatabaseContext <OAuthDbContext>()), ifAlreadyRegistered: IfAlreadyRegistered.Replace); container.RegisterDelegate <IDataRepository <AppToken> >( resolver => new EntityRepository <AppToken>(DatabaseContextManager.GetDatabaseContext <OAuthDbContext>()), ifAlreadyRegistered: IfAlreadyRegistered.Replace); //override authentication service container.Register <IAuthenticationService, OAuthAuthenticationService>( ifAlreadyRegistered: IfAlreadyRegistered.Replace); }
public void RegisterDependencies(IContainer container) { container.Register <IClientService, ClientService>(); container.Register <IAppTokenService, AppTokenService>(); container.Register <IDatabaseContext>(made: Made.Of(() => DatabaseContextManager.GetDatabaseContext <OAuthDbContext>()), serviceKey: ContextServiceKey, reuse: Reuse.InWebRequest); container.RegisterDelegate <IDataRepository <OAuthClient> >( resolver => new EntityRepository <OAuthClient>(ContextServiceKey), ifAlreadyRegistered: IfAlreadyRegistered.Replace, reuse: Reuse.Singleton); container.RegisterDelegate <IDataRepository <AppToken> >( resolver => new EntityRepository <AppToken>(ContextServiceKey), ifAlreadyRegistered: IfAlreadyRegistered.Replace, reuse: Reuse.Singleton); //override authentication service container.Register <IAuthenticationService, OAuthAuthenticationService>( ifAlreadyRegistered: IfAlreadyRegistered.Replace, reuse: Reuse.InWebRequest); }
public OAuthDbContext Create() { return(DatabaseContextManager.GetDatabaseContext <OAuthDbContext>()); }
public void RegisterDependencies(IContainer container) { //http context container.RegisterInstance <HttpContextBase>(new HttpContextWrapper(HttpContext.Current) as HttpContextBase, new SingletonReuse()); //cache provider container.Register <ICacheProvider, HttpCacheProvider>(reuse: Reuse.Singleton); // settings register for access across app container.Register <IDatabaseSettings>(made: Made.Of(() => new DatabaseSettings()), reuse: Reuse.Singleton); //data provider : TODO: Use settings to determine the support for other providers container.Register <IDatabaseProvider>(made: Made.Of(() => new SqlServerDatabaseProvider()), reuse: Reuse.Singleton); //database context container.Register <IDatabaseContext>(made: Made.Of(() => DatabaseContextManager.GetDatabaseContext()), reuse: Reuse.InWebRequest); //and respositories container.Register(typeof(IDataRepository <>), typeof(EntityRepository <>), made: Made.Of(FactoryMethod.ConstructorWithResolvableArguments), reuse: Reuse.InResolutionScope); var asm = AssemblyLoader.LoadBinDirectoryAssemblies(); //services //to register services, we need to get all types from services assembly and register each of them; var serviceAssembly = asm.First(x => x.FullName.Contains("mobSocial.Services")); var serviceTypes = serviceAssembly.GetTypes(). Where(type => type.IsPublic && // get public types !type.IsAbstract && // which are not interfaces nor abstract type.GetInterfaces().Length != 0); // which implementing some interface(s) container.RegisterMany(serviceTypes, reuse: Reuse.InResolutionScope); //we need a trasient reporter service rather than singleton container.Register <IVerboseReporterService, VerboseReporterService>(reuse: Reuse.InWebRequest, ifAlreadyRegistered: IfAlreadyRegistered.Replace); //settings var allSettingTypes = TypeFinder.ClassesOfType <ISettingGroup>(); foreach (var settingType in allSettingTypes) { var type = settingType; container.RegisterDelegate(type, resolver => { var instance = (ISettingGroup)Activator.CreateInstance(type); resolver.Resolve <ISettingService>().LoadSettings(instance); return(instance); }, reuse: Reuse.Singleton); } //and ofcourse the page generator container.Register <IPageGenerator, PageGenerator>(reuse: Reuse.Singleton); //event publishers and consumers container.Register <IEventPublisherService, EventPublisherService>(reuse: Reuse.Singleton); //all consumers which are not interfaces //find all event consumer types var allConsumerTypes = asm .Where(x => x.FullName.StartsWith("mobSocial")) .SelectMany(x => { try { return(x.GetTypes()); } catch { return(new Type[0]); } }) .Where(type => type.IsPublic && // get public types type.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEventConsumer <>)) && !type.IsAbstract); // which implementing some interface(s) //all consumers which are not interfaces container.RegisterMany(allConsumerTypes); //user id provider for SignalR container.Register <IUserIdProvider, SignalRUserIdProvider>(); //register authentication service inwebrequest container.Register <IAuthenticationService, AuthenticationService>(reuse: Reuse.InWebRequest, ifAlreadyRegistered: IfAlreadyRegistered.Replace); //overridable providers container.Register <IRoleNameProvider, RoleNameProvider>(reuse: Reuse.Singleton); }