当前位置: 首页>>代码示例>>C#>>正文


C# ContainerBuilder.Update方法代码示例

本文整理汇总了C#中ContainerBuilder.Update方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.Update方法的具体用法?C# ContainerBuilder.Update怎么用?C# ContainerBuilder.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanResolveReturnsTrueWhenMatchingTypeIsRegistered

        public void CanResolveReturnsTrueWhenMatchingTypeIsRegistered()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object());
            builder.Update(_container);

            Assert.True(_provider.CanResolve<object>());
        }
开发者ID:baumerik,项目名称:Autofac.Extras.MvvmCross,代码行数:8,代码来源:AutofacMvxIocProviderFixture.cs

示例2: GetSingletonThrowsDependencyResolutionExceptionIfTypeRegisteredButNotAsSingleton

        public void GetSingletonThrowsDependencyResolutionExceptionIfTypeRegisteredButNotAsSingleton()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object());
            builder.Update(_container);

            Assert.Throws<DependencyResolutionException>(() => _provider.GetSingleton<object>());
        }
开发者ID:baumerik,项目名称:Autofac.Extras.MvvmCross,代码行数:8,代码来源:AutofacMvxIocProviderFixture.cs

示例3: GetSingletonReturnsSingletonIfTypeRegisteredAsSingleton

        public void GetSingletonReturnsSingletonIfTypeRegisteredAsSingleton()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object()).SingleInstance();
            builder.Update(container);

            Assert.That(provider.GetSingleton<object>(), Is.TypeOf<object>());
            Assert.That(provider.GetSingleton<object>(), Is.SameAs(provider.GetSingleton<object>()));
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:9,代码来源:AutofacMvxIocProviderFixture.cs

示例4: GetSingletonReturnsSingletonIfTypeRegisteredAsSingleton

        public void GetSingletonReturnsSingletonIfTypeRegisteredAsSingleton()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object()).SingleInstance();
            builder.Update(_container);

            Assert.IsType<object>(_provider.GetSingleton<object>());
            Assert.Same(_provider.GetSingleton<object>(), _provider.GetSingleton<object>());
        }
开发者ID:baumerik,项目名称:Autofac.Extras.MvvmCross,代码行数:9,代码来源:AutofacMvxIocProviderFixture.cs

示例5: ResolveCreateAndIoCConstructReturnsRegisteredType

        public void ResolveCreateAndIoCConstructReturnsRegisteredType()
        {
            var builder = new ContainerBuilder();
            builder.Register(c => new object());
            builder.Update(_container);

            Assert.IsType<object>(_provider.Resolve<object>());
            Assert.IsType<object>(_provider.Create<object>());
            Assert.IsType<object>(_provider.IoCConstruct<object>());
        }
开发者ID:baumerik,项目名称:Autofac.Extras.MvvmCross,代码行数:10,代码来源:AutofacMvxIocProviderFixture.cs

示例6: RegistrationsMadeByUpdatingAChildScopeDoNotAppearInTheParentScope

 public void RegistrationsMadeByUpdatingAChildScopeDoNotAppearInTheParentScope()
 {
     var container = new ContainerBuilder().Build();
     var childScope = container.BeginLifetimeScope();
     var updater = new ContainerBuilder();
     updater.RegisterType<object>();
     updater.Update(childScope.ComponentRegistry);
     Assert.True(childScope.IsRegistered<object>());
     Assert.False(container.IsRegistered<object>());
 }
开发者ID:arronchen,项目名称:Autofac,代码行数:10,代码来源:CopyOnWriteRegistryTests.cs

示例7: UpdateScopeWithHttpRequestMessage

        /// <summary>
        /// Updates the current dependency scope with current HTTP request message.
        /// </summary>
        /// <param name="request">The HTTP request message.</param>
        internal static void UpdateScopeWithHttpRequestMessage(HttpRequestMessage request)
        {
            var scope = request.GetDependencyScope();
            var requestScope = scope.GetRequestLifetimeScope();
            if (requestScope == null) return;

            var registry = requestScope.ComponentRegistry;
            var builder = new ContainerBuilder();
            builder.Register(c => request).InstancePerApiRequest();
            builder.Update(registry);
        }
开发者ID:yuleyule66,项目名称:autofac,代码行数:15,代码来源:CurrentRequestHandler.cs

示例8: Register

        public static void Register(global::Autofac.IContainer container, MultipleBinding binding)
        {
            var builder = new ContainerBuilder();

            var registration = builder.RegisterTypes(binding.Services.ToArray());

            if (binding.BindTo.Count > 0)
                registration = registration.As(binding.BindTo.ToArray());

            ApplyLifestyleMultiple(registration, binding.Lifestyle);

            builder.Update(container);
        }
开发者ID:ialekseev,项目名称:Anodyne,代码行数:13,代码来源:AutofacContainerRegistrator.cs

示例9: EnableCompositionIntegration

        /// <summary>
        ///   Enables Managed Extensibility Framework two-way integration.
        /// </summary>
        /// <param name = "container">Target container.</param>
        /// <returns>
        ///   <see cref = "CompositionIntegration" /> instance.
        /// </returns>
        public static CompositionIntegration EnableCompositionIntegration(this IComponentContext container)
        {
            lock (container)
            {
                if (!container.IsRegistered<CompositionIntegration>())
                {
                    var builder = new ContainerBuilder();
                    builder.EnableCompositionIntegration();
                    builder.Update(container.ComponentRegistry);
                }

                return container.Resolve<CompositionIntegration>();
            }
        }
开发者ID:doublekill,项目名称:MefContrib,代码行数:21,代码来源:ContainerExtensions.cs

示例10: AutofacDependencyResolver

        /// <summary>
        /// Initializes a new instance of the <see cref="AutofacDependencyResolver"/> class.
        /// </summary>
        /// <param name="container">The container that nested lifetime scopes will be create from.</param>
        public AutofacDependencyResolver(ILifetimeScope container)
        {
            if (container == null) throw new ArgumentNullException("container");
            _container = container;

            // Issue 351: Register the AutofacDependencyResolver with
            // the request lifetime scope so the current resolver can
            // be retrieved without having to cast it directly to
            // this specific type.
            // Issue 554: Register the AutofacDependencyResolver here
            // because when using the OWIN pipeline there is no other
            // chance to do so before a per-request lifetime scope is
            // created.
            var updateBuilder = new ContainerBuilder();
            updateBuilder.RegisterInstance(this).As<AutofacDependencyResolver>();
            updateBuilder.Update(container.ComponentRegistry);
        }
开发者ID:jdarsie,项目名称:Autofac,代码行数:21,代码来源:AutofacDependencyResolver.cs

示例11: PrepareCompositionContainer

        private CompositionContainer PrepareCompositionContainer()
        {
            // Create the MEF container based on the catalog
            var container = new CompositionContainer(_aggregateCatalog, _providers);

            // If desired, register an instance of CompositionContainer and Autofac container in MEF,
            // this will also make CompositionContainer available to the Autofac
            if (Register)
            {
                // Create composition batch and add the MEF container and the Autofac
                // container to the MEF
                var batch = new CompositionBatch();
                batch.AddExportedValue(AutofacCompositionContainerName, container);
                batch.AddExportedValue(_context);
                container.Compose(batch);

                // Create a container builder and register the composition container in Autofac.
                var builder = new ContainerBuilder();
                builder.RegisterInstance(container).OwnedByLifetimeScope();
                builder.Update(_context.ComponentRegistry);
            }

            return container;
        }
开发者ID:grozeille,项目名称:MefContrib,代码行数:24,代码来源:CompositionIntegration.cs

示例12: ConfigureAutofac

 private void ConfigureAutofac()
 {
     var registrationSource = new MefRegistrationSource(CompositionContainer);
     var builder = new ContainerBuilder();
     builder.RegisterSource(registrationSource);
     builder.Update(_context.ComponentRegistry);
 }
开发者ID:grozeille,项目名称:MefContrib,代码行数:7,代码来源:CompositionIntegration.cs

示例13: RegisterType

        /// <summary>
        /// Registers the service and its implementation with the lifetime behavior.
        /// </summary>
        /// <param name="serviceType">Type of the service.</param>
        /// <param name="implementationType">Type of the implementation.</param>
        /// <param name="lifetime">The lifetime of the service.</param>
        /// <returns></returns>
        public override IServiceRegistrar RegisterType(Type serviceType, Type implementationType, LifetimeType lifetime)
        {
            Invariant.IsNotNull(serviceType, "serviceType");
            Invariant.IsNotNull(implementationType, "implementationType");

            var builder = new ContainerBuilder();

            var registration = builder.RegisterType(implementationType).As(serviceType);

            switch (lifetime)
            {
                case LifetimeType.PerRequest:
                    registration.InstancePerHttpRequest();
                    break;
                case LifetimeType.Singleton:
                    registration.SingleInstance();
                    break;
                default:
                    registration.InstancePerDependency();
                    break;
            }

            builder.Update(Container.ComponentRegistry);

            return this;
        }
开发者ID:AlexBar,项目名称:Autofac,代码行数:33,代码来源:AutofacAdapter.cs

示例14: RegisterInstance

        /// <summary>
        /// Registers the instance as singleton.
        /// </summary>
        /// <param name="serviceType">Type of the service.</param>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public override IServiceRegistrar RegisterInstance(Type serviceType, object instance)
        {
            Invariant.IsNotNull(serviceType, "serviceType");
            Invariant.IsNotNull(instance, "instance");

            var builder = new ContainerBuilder();

            builder.RegisterInstance(instance).As(serviceType).ExternallyOwned();

            builder.Update(Container.ComponentRegistry);

            return this;
        }
开发者ID:AlexBar,项目名称:Autofac,代码行数:19,代码来源:AutofacAdapter.cs

示例15: AutoActivate_ContainerUpdateDoesNotAutoActivateExistingComponents

        public void AutoActivate_ContainerUpdateDoesNotAutoActivateExistingComponents()
        {
            int firstCount = 0;
            var builder = new ContainerBuilder();
            builder.RegisterType<MyComponent2>().AutoActivate().OnActivated(e => firstCount++);
            var container = builder.Build();
            Assert.AreEqual(1, firstCount, "The instance component wasn't properly auto activated.");

            int secondCount = 0;
            var builder2 = new ContainerBuilder();
            builder2.RegisterType<MyComponent>().AutoActivate().OnActivated(e => secondCount++);
            builder2.Update(container);
            Assert.AreEqual(1, firstCount, "The first instance component was incorrectly re-activated.");
            Assert.AreEqual(1, secondCount, "The second instance component wasn't properly auto activated.");
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:15,代码来源:RegistrationExtensionsTests.cs


注:本文中的ContainerBuilder.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。