private static void ConfigureContainer() { Container = new Container(); // Basic test first Container.Register<IClient, TestClient>(); // Singletons can be set up using Reuse - demo this by getting an instance, updating value, then resolving a new instance Container.Register<ISingletonClient, SingletonClient>(Reuse.Singleton); // Registering with a primitive type to be passed to constructor Container.Register<IServiceWithParameter, ServiceWithParameter>(Made.Of(() => new ServiceWithParameter(Arg.Index<string>(0)), requestIgnored => "this is the parameter")); // Then registering a complex object instance to be used Container.Register<TestObject>(); var testObj = new TestObject { ObjectName = "Ian", ObjectType = "Person" }; // Register the instance above (into the container) - giving it an Id ("serviceKey") = "obj1" Container.RegisterInstance<TestObject>(testObj, serviceKey: "obj1"); // Register ServiceWithTypeParameter - saying "When you make me a ServiceWithTypeParameter; and a contructor needs a TestObject - use the one with Id "obj1" Container.Register<IServiceWithTypeParameter, ServiceWithTypeParameter>(made: Parameters.Of.Type<TestObject>(serviceKey: "obj1")); // And finally multiple implementations // Registering multiple interface implementations using an enum key Container.Register<IMultipleImplementations, MultipleImplementationOne>(serviceKey: InterfaceKey.FirstKey); Container.Register<IMultipleImplementations, MultipleImplementationTwo>(serviceKey: InterfaceKey.SecondKey); }
public void test_lazy_resolve_and_resolutionscope_reuse() { var container = new Container(); container.Register <Component>(Reuse.InResolutionScope); container.Register <CreationContext>(Reuse.InResolutionScope); container.Register <Factory>(Reuse.Transient); var object1 = new object(); var factory1 = container.Resolve <Factory>(); factory1.Parameter = object1; var object2 = new object(); var factory2 = container.Resolve <Factory>(); factory2.Parameter = object2; var component1 = factory1.CreateComponent(); var component2 = factory2.CreateComponent(); Assert.AreSame(component1.Parameter, object1); Assert.AreNotSame(component1.Parameter, component2.Parameter); }
private static void SetupViewCommands(Container container) { container.Register<NameInputViewCommand>(); container.Register<NameAndScoreInputViewCommand>(); container.Register<DifficultyManagementViewCommand>(); container.Register<NameAndLevelInputViewCommand>(); container.Register<LogEntryInputViewCommand>(); }
public static IContainer BootstrapIoCContainer() { var container = new Container(); container.Register<IEVEBootstrap, EVEBootstrap>(); container.Register<IExecuteEVEActions, EveActionExecutor>(); container.Register<IQuickAutopilotLogic, QuickAutopilotLogic>(); return container; }
public static DryIoc.IContainer PrepareDryIoc() { var container = new Container(); container.Register <Parameter1>(Reuse.Transient); container.Register <Parameter2>(Reuse.Singleton); container.Register <Parameter3>(Reuse.Scoped); container.Register <ScopedBlah>(Reuse.Scoped); return(container); }
internal static void Register(DryIoc.Container container) { container.Register <AppTrayViewModel>(Reuse.Singleton); container.Register <AppTrayView>(Reuse.Singleton); container.Register <ITrayTooltipNotifier, TrayTooltipNotifier>(Reuse.Singleton); //#if DEBUG // container.RegisterInitializer<object>((service, resolver) => // Trace.TraceWarning($"RESOLVED obj: {service.GetType()}")); //#endif // container.Register<ICoreDataConnection, CoreDataConnection>(Reuse.Singleton); }
private static void SetupViewModels(Container container) { container.Register<IMainViewModel, MainViewModel>(); container.Register<INameInputViewModel, NameInputViewModel>(); container.Register<IDifficultyLevelScaleManagementViewModel, DifficultyLevelScaleManagementViewModel>(); container.Register<IDifficultyLevelManagementViewModel, DifficultyLevelManagementViewModel>(); container.Register<INameAndScoreInputViewModel, NameAndScoreInputViewModel>(); container.Register<IDifficultyManagementViewModel, DifficultyManagementViewModel>(); container.Register<INameAndLevelInputViewModel, NameAndLevelInputViewModel>(); container.Register<ILogEntryInputViewModel, LogEntryInputViewModel>(); container.Register<ILogItemViewModel, LogItemViewModel>(); container.Register<IVariationItemViewModel, VariationItemViewModel>(); }
private static void RegisterDaos(Container container) { container.Register<ICountryDao, CountryDao>(); container.Register<IAreaDao, AreaDao>(); container.Register<ISummitGroupDao, SummitGroupDao>(); container.Register<ISummitDao, SummitDao>(); container.Register<IRoutesDao, RouteDao>(); container.Register<IDifficultyLevelScaleDao, DifficultyLevelScaleDao>(); container.Register<IDifficultyLevelDao, DifficultyLevelDao>(); container.Register<IVariationDao, VariationDao>(); container.Register<ILogEntryDao, LogEntryDao>(); }
private static void RegisterServices(Container container) { container.Register<ICountryService, CountryService>(); container.Register<IAreaService, AreaService>(); container.Register<ISummitGroupService, SummitGroupService>(); container.Register<ISummitService, SummitService>(); container.Register<IRouteService, RouteService>(); container.Register<IVariationService, VariationService>(); container.Register<ILogEntryService, LogEntryService>(); container.Register<IDifficultyLevelScaleService, DifficultyLevelScaleService>(); container.Register<IDifficultyLevelService, DifficultyLevelService>(); }
public void DryIoc() { var container = new DryIoc.Container(); foreach (var type in _types) { container.Register(type, type); } int length = 0; if (Scenario == ResolveScenario.ResolveOne) { length = 1; } else if (Scenario == ResolveScenario.ResolveHalf) { length = _types.Length / 2; } else if (Scenario == ResolveScenario.ResolveAll) { length = _types.Length; } for (var i = 0; i < length; i++) { container.Resolve(_types[i]); } container.Dispose(); }
internal static void Register(DryIoc.Container container) { Type getImplType(Request r) => r.Parent.ImplementationType; // https://bitbucket.org/dadhi/dryioc/wiki/ExamplesContextBasedResolution container.Register( made: Made.Of(() => LogManager.GetCurrentClassLogger(Arg.Index <Type>(0)), getImplType), setup: Setup.With(condition: req => req.Parent.ImplementationType != null), reuse: Reuse.Transient); container.UseInstance(new EnvInfo()); container.Register <ISettingsService, SettingsService>(Reuse.Singleton); container.Register(typeof(IShell <>), typeof(CommandPromptShell), Reuse.Singleton); // reg open gen https://bitbucket.org/dadhi/dryioc/wiki/OpenGenerics container.Register <IWebBrowser, WebBrowser>(Reuse.Singleton); }
public IContainer CreateContainer() { var assemblies = new List <Assembly>() { GetType().Assembly }; var container = new DryIoc.Container(rules => { rules.WithoutThrowOnRegisteringDisposableTransient() .WithAutoConcreteTypeResolution() .With(FactoryMethod.ConstructorWithResolvableArguments) .WithoutThrowOnRegisteringDisposableTransient() .WithFuncAndLazyWithoutRegistration() .WithDefaultIfAlreadyRegistered(IfAlreadyRegistered.Replace); if (Device.RuntimePlatform == Device.iOS) { rules = rules.WithoutFastExpressionCompiler(); } return(rules); }); SetupLogging(container); RegisterPages(container, assemblies); RegisterServices(container, assemblies); RegisterViewModels(container, assemblies); container.Register <IReloadManager, ReloadManager>(); return(container); }
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); }
private InversionOfControlContainer() { container = new Container(rules => rules.WithoutThrowOnRegisteringDisposableTransient()); container.Register<INewsService, NewsService>(Reuse.Singleton); container.Register<INewsDao, NewsDao>(Reuse.Singleton); container.Register<IProvider, Provider>(Reuse.Singleton); container.Register<IPersonDao, PersonDao>(Reuse.Singleton); container.Register<IPersonService, PersonService>(Reuse.Singleton); container.Register<IUserSevice, UserService>(Reuse.Singleton); container.Register<IUserDao, UserDao>(Reuse.Singleton); container.Register<ICommentService, CommentService>(Reuse.Singleton); container.Register<ICommentDao, CommentDao>(Reuse.Singleton); }
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); }
internal static DryIoc.IContainer Compose() { var c = new DryIoc.Container(); c.Register <DirectoriesViewModel>(Reuse.Singleton); c.Register <SyncsViewModel>(Reuse.Singleton); c.Register <MainViewModel>(Reuse.Singleton); c.Register <IBusyStack, BusyStack>(Reuse.Transient); c.UseInstance(ScarletCommandBuilder.Default); c.UseInstance(ScarletCommandManager.Default); c.UseInstance(ScarletDispatcher.Default); c.UseInstance(ScarletExitService.Default); c.UseInstance(ScarletMessenger.Default); c.UseInstance(ScarletWeakEventManager.Default); return(c); }
static void Main(string[] args) { var container = new DryIoc.Container(); container.Register <IMySuperService, MySuperServiceImpl>(Reuse.Transient); container.Register <IMyWorker, MyWorkerImpl>(); var worker = container.Resolve <IMyWorker>(); worker.Work(); var worker2 = container.Resolve <IMyWorker>(); worker2.Work(); System.Console.ReadLine(); }
static void Main(string[] args) { Container container = new Container(); container.Register<ICalculo, Soma>(); container.Register<ICalculo, Subtracao>(); container.Register<Calculadora>(Reuse.Singleton); Calculadora calculadora = container.Resolve<Calculadora>(); calculadora.EfetuarCalculos(500, 200); IEnumerable<ICalculo> calculos = container.Resolve<IEnumerable<ICalculo>>(); foreach (var calculo in calculos) { var result = calculo.Calcular(100, 50); Console.WriteLine($"Resultado: {result}"); } Console.Read(); }
public static IContainer BuildContainer() { var container = new DryIoc.Container(); container.Register <SampleDbContext>(reuse: Reuse.Scoped); container.Register <TraceInterceptor>(reuse: Reuse.Transient); container.Register <TraceInterceptorAsync>(reuse: Reuse.Transient); container.RegisterMany( typeof(ICustomerFindService).Assembly.GetTypes().Where(x => x.IsDependencyComponent()), serviceTypeCondition: t => t.IsComponentInterface(), reuse: Reuse.Scoped, ifAlreadyRegistered: IfAlreadyRegistered.Replace ); container.Intercept <TraceInterceptor>(t => t.IsComponentInterface()); return(container); }
public void container_can_resolve_personlistviewmodel() { var ass = Assembly.GetAssembly(typeof(PersonListViewModel)); var container = new Container(); container.Register(typeof (IRepository<Person>), typeof (TestPersonRepository)); container = container.RegisterViewModels(ass); var personListVm = container.Resolve<IListViewModel<Person>>(); Assert.IsNotNull(personListVm, "PersonListViewModel could not be resolved"); }
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 ContainerTests() { LightInjectContainer .Register <ITransient1, Transient1>() .Register <ITransient2, Transient2>() .Register <ITransient3, Transient3>() .Register <ISingleton1, Singleton1>(new PerContainerLifetime()) .Register <ISingleton2, Singleton2>(new PerContainerLifetime()) .Register <ISingleton3, Singleton3>(new PerContainerLifetime()); DryIocContainer.Register <ITransient1, Transient1>(); DryIocContainer.Register <ITransient2, Transient2>(); DryIocContainer.Register <ITransient3, Transient3>(); DryIocContainer.Register <ISingleton1, Singleton1>(); DryIocContainer.Register <ISingleton2, Singleton2>(); DryIocContainer.Register <ISingleton3, Singleton3>(); GraceContainer.Configure(ioc => { ioc.Export <Transient1>().As <ITransient1>(); ioc.Export <Transient2>().As <ITransient2>(); ioc.Export <Transient3>().As <ITransient3>(); ioc.Export <Singleton1>().As <ISingleton1>().Lifestyle.Singleton(); ioc.Export <Singleton2>().As <ISingleton2>().Lifestyle.Singleton(); ioc.Export <Singleton3>().As <ISingleton3>().Lifestyle.Singleton(); }); }
public static void Main(string[] args) { var dryIoc = new DryIoc.Container(); ContainerRegistrar.Register((x, y) => dryIoc.Register(x, y)); dryIoc.Register <ILogger, ConsoleLogger>(); var unity = new UnityContainer(); ContainerRegistrar.Register((x, y) => unity.RegisterType(x, y)); unity.RegisterType <ILogger, ConsoleLogger>(); var structureMap = new StructureMap.Container(c => { ContainerRegistrar.Register((x, y) => c.For(x).Use(y)); c.For <ILogger>().Use <ConsoleLogger>(); }); var autofac = new Autofac.ContainerBuilder(); ContainerRegistrar.Register((x, y) => autofac.RegisterType(x).As(y)); autofac.RegisterType <ILogger>().As <ConsoleLogger>(); }
public SimpleObjectBenchmarks() { var serviceContainer = new ServiceContainer(); serviceContainer.Transients.AddType <IUserService, UserService1>(); serviceContainer.Transients.AddType <IUserService, UserService2>(); serviceContainer.Transients.AddType <IUserService, UserService>(); serviceContainer.Transients.AddType(typeof(IRepository <>), typeof(Repository <>)); serviceResolver = serviceContainer.Build(); var serviceCollection = new ServiceCollection(); serviceCollection.AddTransient <IUserService, UserService1>(); serviceCollection.AddTransient <IUserService, UserService2>(); serviceCollection.AddTransient <IUserService, UserService>(); serviceCollection.AddTransient(typeof(IRepository <>), typeof(Repository <>)); serviceProvider = serviceCollection.BuildServiceProvider(); var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterType <UserService1>().As <IUserService>().InstancePerDependency(); containerBuilder.RegisterType <UserService2>().As <IUserService>().InstancePerDependency(); containerBuilder.RegisterGeneric(typeof(Repository <>)).As(typeof(IRepository <>)); containerBuilder.RegisterType <UserService>().As <IUserService>().InstancePerDependency(); autofacContainer = containerBuilder.Build(); zkWebContainer = new ZKWebContainer(); zkWebContainer.Register <IUserService, UserService1>(ReuseType.Transient, null); zkWebContainer.Register <IUserService, UserService2>(ReuseType.Transient, null); zkWebContainer.Register <IUserService, UserService>(ReuseType.Transient, null); zkWebContainer.Register(typeof(IRepository <>), typeof(Repository <>), ReuseType.Transient, null); dryIocContainer = new DryIocContainer(); dryIocContainer.Register <IUserService, UserService1>(); dryIocContainer.Register <IUserService, UserService2>(); dryIocContainer.Register <IUserService, UserService>(); dryIocContainer.Register(typeof(IRepository <>), typeof(Repository <>)); }
public static void RegisterIoC(HttpConfiguration config) { var appCfg = new AppConfiguration(); var di = new DryIoc.Container().WithWebApi(config); var creds = new GraphCredentials { ClientId = appCfg.ClientId, // "5c642f80-ae79-4d3a-a753-5498eeb2e7d0", Key = appCfg.Key, //"6WxvoAUri6JXdEDIdTISz/SfCRZa7NUZCL7nAl4lcoM=", Tenant = appCfg.TenantId //"e58cae89-8f91-4f69-8cce-51abf1d13b44" }; di.Register <IGroupRepository, GroupRepository>(setup: Setup.With(trackDisposableTransient: true)); di.Register <IUserGroupManager, UserGroupManager>(Made.Of(() => new UserGroupManager(creds, Arg.Of <IGroupRepository>()))); di.Register <IAdminGroupManager, AdminGroupManager>(Made.Of(() => new AdminGroupManager(creds, Arg.Of <IGroupRepository>()))); var errors = di.VerifyResolutions(); Debug.Assert(errors.Length == 0); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddApplicationInsightsTelemetry(Configuration); services.AddMvc(); // DryIOC // http://stackoverflow.com/questions/36179819/dryioc-asp-net-5-web-api var container = new DryIoc.Container().WithDependencyInjectionAdapter(services); container.Register <ICustomerRepository, CustomerRepository>(Reuse.Singleton); var serviceProvider = container.Resolve <IServiceProvider>(); return(serviceProvider); }
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); }
public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); WebApiConfig.Register(config); var container = new DryIoc.Container(); // ReplaceControllersIOCLifeCircle(config, container); //dry container.Register <ILixo, Lixo>(Reuse.Transient, ifAlreadyRegistered: IfAlreadyRegistered.Replace); var modelBuilder = new ODataConventionModelBuilder(config); modelBuilder.EnableLowerCamelCase(); config.EnableCaseInsensitive(true); modelBuilder.EntitySet <Person>("People"); var server = new HttpServer(config); config.MapODataServiceRoute( ODataConstants.RouteName, ODataConstants.RoutePrefix, modelBuilder.GetEdmModel(), new DefaultODataBatchHandler(server) ); //app.UseDryIocOwinMiddleware(container); app .UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll) .UseWebApi(server) .UseDryIocWithTransientControllers(container, config) ; }
internal static IBus Build(Config configuration) { var logger = configuration.Logger; logger.Debug("Constructing bus..."); _container = _container ?? new Container(); _container.Register(configuration.Logger.GetType(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.Register(configuration.Serializer.GetType(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.Register(configuration.Compressor.GetType(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.Register(configuration.Transport.GetType(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.CommandPipeline.GetCommandHandlerTypes(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.CommandPipeline.GetCommandTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.CommandPipeline.GetPreHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.CommandPipeline.GetPostHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.CommandPipeline.GetErrorHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.EventPipeline.GetCompetingEventHandlerTypes(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.EventPipeline.GetMulticastEventHandlerTypes(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.EventPipeline.GetEventTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.EventPipeline.GetPreHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.EventPipeline.GetPostHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.EventPipeline.GetErrorHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.RequestResponsePipeline.GetRequestHandlerTypes(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.RequestResponsePipeline.GetMulticastRequestHandlerTypes(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.RequestResponsePipeline.GetRequestTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.RequestResponsePipeline.GetResponseTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.RequestResponsePipeline.GetPreHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.RequestResponsePipeline.GetPostHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.RegisterMany(configuration.RequestResponsePipeline.GetErrorHookTypes(), ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.Register<IPipeline, CommandPipeline>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.Register<IPipeline, EventPipeline>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.Register<IPipeline, RequestResponsePipeline>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); _container.Register<IBus, Bus>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep); return _container.Resolve<IBus>(); }
public void Configuration(IAppBuilder app) { var webApiConfig = new HttpConfiguration(); var hubConfig = new HubConfiguration { EnableJSONP = true, EnableJavaScriptProxies = true }; webApiConfig.MapHttpAttributeRoutes(); webApiConfig.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); webApiConfig.EnableCors( new EnableCorsAttribute("*", "*", "GET, POST, OPTIONS, PUT, DELETE, PATCH") ); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = new WebPhysicalFileSystem(".\\wwwroot") }; var container = new Container() .WithWebApi(webApiConfig) .WithSignalR(Assembly.GetExecutingAssembly()); container.Register<ITest, Test>(); app.Use(new Func<AppFunc, AppFunc>(next => env => Invoke(next, env))) .UseErrorPage(ErrorPageOptions.ShowAll) .UseCors(CorsOptions.AllowAll) .Use(typeof(OwinMiddleWareQueryStringExtractor)) .UseOAuthAuthorizationServer(new OAuthOptions()) .UseJwtBearerAuthentication(new JwtOptions()) .UseAngularServer("/", "/index.html") .UseFileServer(options) .UseWebApi(webApiConfig) .MapSignalR(hubConfig); }
static void Test() { var dry = new DryIoc.Container(); dry.Register <IMetricSubmitter, EnrichMetricsDecorator>( setup: new DecoratorSetup(z => { return(z.Parent.ImplementationType == typeof(SingleWorker)); }, order: 0, useDecorateeReuse: false)); dry.Register <IMetricSubmitter, DefaultMetricSubmitter>(Reuse.Singleton); dry.Register <SingleWorker>(Reuse.Singleton); dry.Register <ScopedWorker>(Reuse.Singleton); var worker = dry.Resolve <SingleWorker>(); Console.WriteLine(worker); var worker2 = dry.Resolve <ScopedWorker>(); Console.WriteLine(worker2); var container = new global::SimpleInjector.Container(); container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle(); container.ForConsumer <BConsumer>() .RegisterSingleton <AInterface, BImplementation>(); container.ForConsumer <AConsumer>() .Register <AInterface, AImplementation>(Lifestyle.Singleton); container.RegisterSingleton <AConsumer>(); container.RegisterDecorator( typeof(AInterface), typeof(AInterfaceDecorator), Lifestyle.Singleton, z => { return(true); }); container.RegisterDecorator( typeof(AInterface), typeof(BInterfaceDecorator), Lifestyle.Singleton, z => { return(true); }); container.Register <SingleWorker>(Lifestyle.Singleton); container.Register <ScopedWorker>(Lifestyle.Scoped); container.RegisterDecorator <IMetricSubmitter, EnrichMetricsDecorator>(); container.RegisterConditional <IMetricSubmitter, ProxyMetricSubmitter>( Lifestyle.Singleton, z => z.Consumer.ImplementationType == typeof(SingleWorker)); container.Verify(); container.GetInstance <SingleWorker>(); using (AsyncScopedLifestyle.BeginScope(container)) { container.GetInstance <ScopedWorker>(); } container.GetInstance <AConsumer>(); container.GetInstance <AConsumer>(); container.GetInstance <BConsumer>(); container.GetInstance <BConsumer>(); }
static public void Main(string[] args) { var _benchmark = new Benchmark(() => new Action(() => new Calculator())); _benchmark.Add("SimpleInjector", () => { var _container = new SimpleInjector.Container(); _container.Register <ICalculator, Calculator>(SimpleInjector.Lifestyle.Transient); return(() => _container.GetInstance <ICalculator>()); }); //TODO : change to test new Puresharp DI recast _benchmark.Add("Puresharp", () => { var _container = new Puresharp.Composition.Container(); _container.Add <ICalculator>(() => new Calculator(), Puresharp.Composition.Lifetime.Volatile); return(() => _container.Enumerable <ICalculator>()); }); //TODO : change to test MEF2 _benchmark.Add("MEF", () => { var _container = new System.Composition.Hosting.ContainerConfiguration().WithAssembly(typeof(ICalculator).Assembly).CreateContainer(); return(() => _container.GetExport <ICalculator>()); }); _benchmark.Add("Castle Windsor", () => { var _container = new WindsorContainer(); _container.Register(Castle.MicroKernel.Registration.Component.For <ICalculator>().ImplementedBy <Calculator>()); return(() => _container.Resolve <ICalculator>()); }); _benchmark.Add("Unity", () => { var _container = new UnityContainer(); _container.RegisterType <ICalculator, Calculator>(); return(() => _container.Resolve <ICalculator>()); }); _benchmark.Add("StuctureMap", () => { var _container = new StructureMap.Container(_Builder => _Builder.For <ICalculator>().Use <Calculator>()); return(() => _container.GetInstance <ICalculator>()); }); _benchmark.Add("DryIoc", () => { var _container = new DryIoc.Container(); _container.Register <ICalculator, Calculator>(); return(() => _container.Resolve <ICalculator>()); }); _benchmark.Add("Autofac", () => { var _builder = new Autofac.ContainerBuilder(); _builder.RegisterType <Calculator>().As <ICalculator>(); var _container = _builder.Build(Autofac.Builder.ContainerBuildOptions.None); return(() => _container.Resolve <ICalculator>()); }); _benchmark.Add("Ninject", () => { var _container = new Ninject.StandardKernel(); _container.Bind <ICalculator>().To <Calculator>(); return(() => _container.Get <ICalculator>()); }); _benchmark.Add("Abioc", () => { var _setup = new Abioc.Registration.RegistrationSetup(); _setup.Register <ICalculator, Calculator>(); var _container = Abioc.ContainerConstruction.Construct(_setup, typeof(ICalculator).Assembly); return(() => _container.GetService <ICalculator>()); }); _benchmark.Add("Grace", () => { var _container = new Grace.DependencyInjection.DependencyInjectionContainer(); _container.Configure(c => c.Export <Calculator>().As <ICalculator>()); return(() => _container.Locate <ICalculator>()); }); _benchmark.Run(Console.WriteLine); }
internal static void Register(DryIoc.Container container) { container.Register <ICoreDataDriveService, CoreDataDriveService>(Reuse.Singleton); container.Register <ILocalStorage, PhysicalStorage>(Reuse.Singleton); }
public void Register <TService, TConcrete>() where TConcrete : TService => _Container.Register <TService, TConcrete>();
private static void RegisterConfigurations(Container container) { container.Register<ILogger, EveDebugLogger>(); }
public TransientBenchmarks() { container .Register <ITransient1, Transient1>() .Register <ITransient2, Transient2>() .Register <ITransient3, Transient3>(); dryIocContainer.Register <ITransient1, Transient1>(); dryIocContainer.Register <ITransient2, Transient2>(); dryIocContainer.Register <ITransient3, Transient3>(); graceContainer.Configure(ioc => { ioc.Export <Transient1>().As <ITransient1>(); ioc.Export <Transient2>().As <ITransient2>(); ioc.Export <Transient3>().As <ITransient3>(); }); }