private IServiceResolver CreateResolver(Action <IServiceRegister> configure)
        {
            var services = new ServiceCollection();
            var adapter  = new ServiceCollectionAdapter(services);

            configure.Invoke(adapter);
            return(services.BuildServiceProvider().GetService <IServiceResolver>());
        }
Пример #2
0
        protected override async Task OnInitialized(object param)
        {
            await base.OnInitialized(param);

            _adapter = await Resolver.Resolve <ServiceCollectionAdapter <string, ItemVm> >()
                       .From(_service.MyNames)
                       .To(Items)
                       .ModifyWith(async(m, vm) => await vm.ReadModel(m, this))
                       .Start();
        }
Пример #3
0
        /// <summary>
        /// Registers the specified module type.
        /// </summary>
        /// <typeparam name="TModule">The type of the module.</typeparam>
        /// <param name="services">The service collection.</param>
        /// <returns>The same <see cref="IServiceCollection"/> instance so that multiple calls can be chained.</returns>
        public static IServiceCollection UseModule <TModule>(this IServiceCollection services)
            where TModule : ICakeModule, new()
        {
            var module = new TModule();

            var adapter = new ServiceCollectionAdapter();

            module.Register(adapter);
            adapter.Transfer(services);

            return(services);
        }
Пример #4
0
        public static IServiceCollection RegisterEasyNetQ(this IServiceCollection serviceCollection, Func <IServiceResolver, ConnectionConfiguration> connectionConfigurationFactory, Action <IServiceRegister> registerServices)
        {
            if (serviceCollection == null)
            {
                throw new ArgumentNullException(nameof(serviceCollection));
            }

            var serviceRegister = new ServiceCollectionAdapter(serviceCollection);

            RabbitHutch.RegisterBus(serviceRegister, connectionConfigurationFactory, registerServices);
            return(serviceCollection);
        }
        public void CreateScope_TransientServiceInSameScope_ShouldBeSingleton()
        {
            var services = new ServiceCollection();
            var adapter  = new ServiceCollectionAdapter(services);

            services.AddScoped <IService, Service>();
            var resolver = services.BuildServiceProvider().GetService <IServiceResolver>();

            IService service1;
            IService service2;

            using (var scope = resolver.CreateScope())
            {
                service1 = scope.Resolve <IService>();
                service2 = scope.Resolve <IService>();
            }

            Assert.Same(service1, service2);
        }