private static IMediator BuildMediator() { var container = new Container(); container.RegisterDelegate<SingleInstanceFactory>(r => serviceType => r.Resolve(serviceType)); container.RegisterDelegate<MultiInstanceFactory>(r => serviceType => r.ResolveMany(serviceType)); container.RegisterInstance(Console.Out); container.RegisterMany(new[] { typeof(IMediator).GetAssembly(), typeof(Ping).GetAssembly() }, type => type.GetTypeInfo().IsInterface); return container.Resolve<IMediator>(); }
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, reuse: Reuse.Singleton); }
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 Locator() { Container = new Container(); Container.Register<IBitmapFactory, PclBitmapFactory>(Reuse.Singleton); Container.Register<IAppSettingsHelper, AppSettingsHelper>(Reuse.Singleton); Container.Register<IDispatcherHelper, DispatcherHelper>(Reuse.Singleton); Container.Register<INotificationManager, NotificationManager>(Reuse.Singleton); Container.Register<ICredentialHelper, CredentialHelper>(Reuse.Singleton); var factory = new AudioticaFactory(DispatcherHelper, AppSettingsHelper, BitmapFactory); Container.Register<IScrobblerService, ScrobblerService>(Reuse.Singleton); Container.Register<SpotifyWebApi>(Reuse.Singleton); Container.Register<ISpotifyService, SpotifyService>(Reuse.Singleton); Container.RegisterDelegate(r => factory.CreateCollectionSqlService(10), Reuse.Singleton); Container.RegisterDelegate(r => factory.CreatePlayerSqlService(4), Reuse.Singleton, named: "BackgroundSql"); Container.RegisterDelegate(r => factory.CreateCollectionService(SqlService, BgSqlService), Reuse.Singleton); Container.Register<Mp3MatchEngine>(Reuse.Singleton); }
protected void Application_Start(object sender, EventArgs e) { WebApiConfig.Register(GlobalConfiguration.Configuration); IContainer container = new Container(); container.Register<IProductRepository, FakeProductRepository>(WebReuse.InRequest); container.RegisterDelegate<ILogger>( resolver => new Logger(s => Debug.WriteLine(s)), Reuse.Singleton); container.Register<ProductsController>(WebReuse.InRequest); container.WithWebApi(GlobalConfiguration.Configuration); }