public void Resolve_single_service_with_multiple_registrations_should_resolve_the_same_way_as_microsoft_di( bool usingScope, ServiceLifetime firstLifetime, ServiceLifetime secondLifetime, Type expectedResolveType) { // arrange var collection = new ServiceCollection(); collection.Add(ServiceDescriptor.Describe(typeof(IService), typeof(ServiceA), firstLifetime)); collection.Add(ServiceDescriptor.Describe(typeof(IService), typeof(ServiceB), secondLifetime)); IServiceProvider msProvider = collection.BuildServiceProvider(); IServiceProvider dryiocProvider = DryIocAdapter.Create(collection); if (usingScope) { msProvider = msProvider.CreateScope().ServiceProvider; dryiocProvider = dryiocProvider.CreateScope().ServiceProvider; } // act var msService = msProvider.GetRequiredService <IService>(); var dryiocService = dryiocProvider.GetRequiredService <IService>(); // assert Assert.IsInstanceOf(expectedResolveType, msService, "Microsoft changed the implementation"); Assert.IsInstanceOf(expectedResolveType, dryiocService, "DryIoc resolves the requested type different than microsofts di implementation"); }
/// <summary> /// 使用Prism注册并初始化容器,需要确保Shiny和Prism使用相同的容器 /// </summary> /// <param name="services"></param> /// <returns></returns> public override IServiceProvider CreateServiceProvider(IServiceCollection services) { ContainerLocator.SetContainerExtension(() => new DryIocContainerExtension()); var container = ContainerLocator.Container.GetContainer(); DryIocAdapter.Populate(container, services); return(container.GetServiceProvider()); }
public override IServiceProvider CreateServiceProvider(IServiceCollection services) { // This registers and initializes the Container with Prism ensuring // that both Shiny & Prism use the same container ContainerLocator.SetContainerExtension(() => new DryIocContainerExtension()); var container = ContainerLocator.Container.GetContainer(); DryIocAdapter.Populate(container, services); return(container.GetServiceProvider()); }
public override IServiceProvider CreateServiceProvider(IServiceCollection services) { var container = new Container(Rules .Default .WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient) .With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments)) .WithFuncAndLazyWithoutRegistration() .WithTrackingDisposableTransients() .WithoutFastExpressionCompiler() .WithFactorySelector(Rules.SelectLastRegisteredFactory()) ); DryIocAdapter.Populate(container, services); Container = container; return(container.GetServiceProvider()); }
public static void Register(HttpConfiguration config) { var adapter = new DryIocAdapter(); var binders = new IBinding[] { new BusinessBinder(), new DaoBinder(), new SharedBinder(), new IoCFrameworkBinder(), }; foreach (var binder in binders) { binder.SetBinding(adapter); } var containerWithMvc = adapter ._container .WithWebApi(config); }
protected override IServiceProvider CreateServiceProvider(IServiceCollection services) => DryIocAdapter.Create(services);
/// <summary>Creates **new** container configured for Microsoft.Extensions.DependencyInjection /// with user provided configuration or by default.</summary> public IContainer CreateBuilder(IServiceCollection services) => _configureContainer?.Invoke(services) ?? DryIocAdapter.Create(services);