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


C# UnityContainer.Dispose方法代码示例

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


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

示例1: BuildUnityContainer

        private static IUnityContainer BuildUnityContainer()
        {
            UnityContainer tempContainer = null;
            UnityContainer container;

            try
            {
                tempContainer = new UnityContainer();

                // Register your container mappings in the config file.
                // It will get loaded into the container with the following call:
                tempContainer.LoadConfiguration();

                container = tempContainer;
                tempContainer = null;
            }
            finally
            {
                if (tempContainer != null)
                {
                    tempContainer.Dispose();
                }
            }

            return container;
        }
开发者ID:sendtorakesh,项目名称:MitchellClaim,代码行数:26,代码来源:Bootstrapper.cs

示例2: OnStartup

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

               UnityContainer container = new UnityContainer();
               var mainView = container.Resolve<MainWindow>();
               container.Dispose();
               mainView.Show();
        }
开发者ID:ReasonSharp,项目名称:MyTestRepo,代码行数:9,代码来源:App.xaml.cs

示例3: DisposingParentDisposesChild

        public void DisposingParentDisposesChild()
        {
            UnityContainer parent = new UnityContainer();
            IUnityContainer child = parent.CreateChildContainer();

            MyDisposableObject spy = new MyDisposableObject();
            child.RegisterInstance(spy);
            parent.Dispose();

            Assert.IsTrue(spy.WasDisposed);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:11,代码来源:ChildContainerFixture.cs

示例4: MefDisposesMefComponentTest

        public void MefDisposesMefComponentTest()
        {
            // Setup
            var unityContainer = new UnityContainer();
            var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            // Register catalog and types
            unityContainer.RegisterCatalog(assemblyCatalog);
            unityContainer.RegisterType<IUnityOnlyComponent, UnityOnlyComponent1>();

            // Test
            var container = unityContainer.Resolve<CompositionContainer>();
            var mefComponentDisposable = container.GetExportedValue<MefComponentDisposable>();
            Assert.That(mefComponentDisposable, Is.Not.Null);
            Assert.That(mefComponentDisposable.GetType(), Is.EqualTo(typeof(MefComponentDisposable)));

            unityContainer.Dispose();

            Assert.IsTrue(mefComponentDisposable.Disposed);
        }
开发者ID:salfab,项目名称:MefContrib,代码行数:20,代码来源:BidirectionalIntegrationTests.cs

示例5: Main

        static void Main(string[] args)
        {
            IUnityContainer container = new UnityContainer();
            try
            {
                container.RegisterType<IUnitOfWork, UnitOfWork>();
                container.RegisterType<IWidgetController, WidgetController>();

                /* Registering ViewModels */

                //Standard ViewModels
                container.RegisterType<IWidgetContainerViewModel, WidgetContainerViewModel>();

                //Control ViewModels
                container.RegisterType<IImageWidgetViewModel, ImageWidgetViewModel>();
                container.RegisterType<ITextWidgetViewModel, TextWidgetViewModel>();

                /* Mapping Model to ViewModel */

                container.RegisterFactory<IWidgetContainer, IWidgetContainerViewModel>().AddDefaultMap();

                container.RegisterFactory<IWidget, IWidgetViewModel>()
                    .AddMap<IImageWidget, IImageWidgetViewModel>()
                    .AddMap<ITextWidget, ITextWidgetViewModel>();

                /* Run Program */

                var controller = container.Resolve<IWidgetController>();
                controller.ShowWidgits(1);

                /* End Program */

                Console.WriteLine();
                Console.WriteLine("Please press any key to continue. . .");
                Console.ReadKey(true);
            }
            finally
            {
                container.Dispose();
            }
        }
开发者ID:jigamiller,项目名称:unitymappingfactory,代码行数:41,代码来源:Program.cs

示例6: Main

        /// <summary>
        /// Method bootstraps application and runs the application
        /// </summary>
        /// <param name="args">Command line arguements passed in</param>
        static void Main(string[] args)
        {
            AutoMapperExtensions.Build();

            var container = new UnityContainer();

            container.RegisterType<IOutputWriter, ConsoleOutputWriter>();

            if (args.Length == 2)
            {

                //Conditional Bootstrapping of the services
                container.RegisterType<IRateDatasSource, TaxRateDb>(new InjectionConstructor(new List<TaxBracket>()));
                container.RegisterType<ISalarySlipService, MonthlySalarySlipService>();
                container.RegisterType<IFileProcessor, SalaryDataFileProcessor>("SalaryProcessor");
                container.RegisterType<IFileProcessor, RatesDataFileProcessor>("RatesProcessor");
                container.RegisterType<ITaxService, TaxCalculationService>();

                //Load tax rates from file
                container.Resolve<IFileProcessor>("RatesProcessor").Run(args[0]);

                //Read and Process salary from file
                container.Resolve<IFileProcessor>("SalaryProcessor").Run(args[1]);

            }
            else
            {
                //printing output writer
                container.Resolve<IOutputWriter>().WriteLine("Application Error - Please provide two paths to a rates and paypacket csv respectively");
            }

            //Console readkey
            System.Console.ReadKey();

            //Dispose Unity Container
            container.Dispose();
        }
开发者ID:KarapaBandit,项目名称:PayApp,代码行数:41,代码来源:Program.cs

示例7: HierarchicalLifetimeManager_Child_Not_Equal_To_Parent

        public void HierarchicalLifetimeManager_Child_Not_Equal_To_Parent()
        {
            // Create parent container
            IUnityContainer parentCtr = new UnityContainer();

            // Register type in parent container
            parentCtr.RegisterType<MyObject>(new HierarchicalLifetimeManager());

            // Create nested child container in parent container
            IUnityContainer childCtr = parentCtr.CreateChildContainer();

            MyObject parentObject1 = parentCtr.Resolve<MyObject>();
            MyObject parentObject2 = parentCtr.Resolve<MyObject>();
            Assert.That(parentObject2.GetHashCode(), Is.EqualTo(parentObject1.GetHashCode()), "paren1 != parent2");

            MyObject childObject = childCtr.Resolve<MyObject>();
            Assert.That(childObject.GetHashCode(), Is.Not.EqualTo(parentObject1.GetHashCode()), "child != parent");

            // Dispose child container
            childCtr.Dispose();

            // Dispose parent container
            parentCtr.Dispose();
        }
开发者ID:constructor-igor,项目名称:TechSugar,代码行数:24,代码来源:UnityChildLifetimeSamples.cs

示例8: Register

        public static void Register(HttpConfiguration config)
        {
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.

            // Web API routes
            config.MapHttpAttributeRoutes();

            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);

            config.Filters.Add(new ExceptionHandlingAttribute());
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            var container = new UnityContainer();

            try
            {
                // repositories used by the application

                container.RegisterType<ConferenceRegistrationDbContext>(new TransientLifetimeManager(), new InjectionConstructor("ConferenceRegistration"));
                container.RegisterType<PaymentsReadDbContext>(new TransientLifetimeManager(), new InjectionConstructor("Payments"));

                var cache = new MemoryCache("ReadModel");
                container.RegisterType<IOrderDao, OrderDao>();
                container.RegisterType<IConferenceDao, CachingConferenceDao>(
                    new ContainerControlledLifetimeManager(),
                    new InjectionConstructor(new ResolvedParameter<ConferenceDao>(), cache));
                container.RegisterType<IPaymentDao, PaymentDao>();

                // configuration specific settings

                var serializer = new JsonTextSerializer();
                container.RegisterInstance<ITextSerializer>(serializer);

                container.RegisterType<IBlobStorage, SqlBlobStorage>(new ContainerControlledLifetimeManager(), new InjectionConstructor("BlobStorage"));
                container.RegisterType<Infrastructure.Sql.Messaging.IMessageSender, MessageSender>(
                    "Commands", new TransientLifetimeManager(), new InjectionConstructor(Database.DefaultConnectionFactory, "SqlBus", "SqlBus.Commands"));
                container.RegisterType<ICommandBus, Infrastructure.Sql.Messaging.CommandBus>(
                    new ContainerControlledLifetimeManager(), new InjectionConstructor(new ResolvedParameter<Infrastructure.Sql.Messaging.IMessageSender>("Commands"), serializer));


                config.DependencyResolver = new UnityResolver(container);

                IEventBus eventBus = null;
//#if LOCAL
            eventBus = new Infrastructure.Sql.Messaging.EventBus(new MessageSender(Database.DefaultConnectionFactory, "SqlBus", "SqlBus.Events"), serializer);
//#else
//                var settings = InfrastructureSettings.Read(HttpContext.Current.Server.MapPath(@"~\bin\Settings.xml")).ServiceBus;

//                if (!MaintenanceMode.IsInMaintainanceMode)
//                {
//                    new ServiceBusConfig(settings).Initialize();
//                }

//                eventBus = new Infrastructure.Azure.Messaging.EventBus(new TopicSender(settings, "conference/events"), new StandardMetadataProvider(), serializer);
//#endif

                container.RegisterInstance<IEventBus>(eventBus);

                var conferenceService = new ConferenceService(eventBus);

                container.RegisterInstance<ConferenceService>(conferenceService);
            }
            catch
            {
                container.Dispose();
                throw;
            }
        }
开发者ID:wayne-o,项目名称:delete-me,代码行数:75,代码来源:WebApiConfig.cs

示例9: CreateUnityContainer

        /// <summary>
        /// Creates an instance of <see cref="Microsoft.Practices.Unity.UnityContainer"/> from configuration using the provided container name.
        /// </summary>
        /// <param name="containerName">Container name to configure.  If containerName is null or empty, the default container is configured.</param>
        /// <returns>Created and configured <see cref="Microsoft.Practices.Unity.UnityContainer"/>.</returns>
        private static IUnityContainer CreateUnityContainer(string containerName)
        {
            IUnityContainer unityContainer = new UnityContainer();
            try
            {
                UnityConfigurationSection section = ConfigurationManager.GetSection(
                    UnityInstanceProvider.UnityConfigurationSectionName) as UnityConfigurationSection;
                if (section != null)
                {
                    if (string.IsNullOrEmpty(containerName))
                    {
                        section.Configure(unityContainer);
                    }
                    else
                    {
                        section.Configure(unityContainer, containerName);
                    }
                }
            }
            catch (Exception)
            {
                unityContainer.Dispose();
                throw;
            }

            return unityContainer;
        }
开发者ID:Cassaba,项目名称:Apworks,代码行数:32,代码来源:UnityInstanceProvider.cs

示例10: DisposingUnityDisposesCompositionContainerTest

        public void DisposingUnityDisposesCompositionContainerTest()
        {
            // Setup
            var unityContainer = new UnityContainer();
            var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            // Add composition support for unity
            unityContainer.AddNewExtension<CompositionIntegration>();
            unityContainer.Configure<CompositionIntegration>().Catalogs.Add(assemblyCatalog);

            var compositionContainer = unityContainer.Resolve<CompositionContainer>();
            unityContainer.Dispose();
            
            Assert.That(delegate
            {
                compositionContainer.GetExport<IMefComponent>();
            }, Throws.TypeOf<ObjectDisposedException>());
        }
开发者ID:doublekill,项目名称:MefContrib,代码行数:18,代码来源:CompositionIntegrationTests.cs

示例11: CreateContainer

        private static UnityContainer CreateContainer()
        {
            var container = new UnityContainer();
            try
            {
                // repositories used by the application

                container.RegisterType<ConferenceRegistrationDbContext>(new TransientLifetimeManager(), new InjectionConstructor("ConferenceRegistration"));
                container.RegisterType<PaymentsReadDbContext>(new TransientLifetimeManager(), new InjectionConstructor("Payments"));

                var cache = new MemoryCache("ReadModel");
                container.RegisterType<IOrderDao, OrderDao>();
                container.RegisterType<IConferenceDao, CachingConferenceDao>(
                    new ContainerControlledLifetimeManager(),
                    new InjectionConstructor(new ResolvedParameter<ConferenceDao>(), cache));
                container.RegisterType<IPaymentDao, PaymentDao>();

                // configuration specific settings

                OnCreateContainer(container);

                return container;
            }
            catch
            {
                container.Dispose();
                throw;
            }
        }
开发者ID:wayne-o,项目名称:delete-me,代码行数:29,代码来源:Global.asax.cs

示例12: WhenDisposingParentChildDisposes

        public void WhenDisposingParentChildDisposes()
        {
            UnityContainer parent = new UnityContainer();
            IUnityContainer child = parent.CreateChildContainer();

            TestContainer3 obj = new TestContainer3();
            child.RegisterInstance<TestContainer3>(obj);

            parent.Dispose();
            Assert.IsTrue(obj.WasDisposed);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:11,代码来源:ChildContainerInterfaceChangeFixture.cs

示例13: DisposeContainerDisposesCachedParsley

        public void DisposeContainerDisposesCachedParsley()
        {
            var container = new UnityContainer();

            var lease = new SlidingLease(TimeSpan.FromMinutes(1));
            var cache = new CacheLifetimeManager(lease);
            container.RegisterType<IIngredient, Parsley>(cache);

            var ingredient = container.Resolve<IIngredient>();

            container.Dispose();

            var parsley = Assert.IsAssignableFrom<Parsley>(ingredient);
            Assert.True(parsley.IsDisposed);
        }
开发者ID:mesta1,项目名称:dli.net_sourcecode,代码行数:15,代码来源:MenuFacts.cs

示例14: CanDisposeChildWithoutDisposingParent

        public void CanDisposeChildWithoutDisposingParent()
        {
            MyDisposableObject parentSpy = new MyDisposableObject();
            MyDisposableObject childSpy = new MyDisposableObject();
            UnityContainer parent = new UnityContainer();

            parent.RegisterInstance(parentSpy);
            IUnityContainer child = parent.CreateChildContainer()
                .RegisterInstance(childSpy);
            child.Dispose();

            Assert.IsFalse(parentSpy.WasDisposed);
            Assert.IsTrue(childSpy.WasDisposed);

            childSpy.WasDisposed = false;
            parent.Dispose();

            Assert.IsTrue(parentSpy.WasDisposed);
            Assert.IsFalse(childSpy.WasDisposed);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:20,代码来源:ChildContainerFixture.cs

示例15: GetObjectAfterDispose

        public void GetObjectAfterDispose()
        {
            UnityContainer parent = new UnityContainer();
            parent.RegisterType<Temp>("First", new ContainerControlledLifetimeManager());

            IUnityContainer child = parent.CreateChildContainer();
            child.RegisterType<ITemporary>("First", new ContainerControlledLifetimeManager());
            parent.Dispose();
            AssertHelper.ThrowsException<ResolutionFailedException>(() => child.Resolve<ITemporary>("First"));
        }
开发者ID:CFMITL,项目名称:unity,代码行数:10,代码来源:ChildContainerFixture.cs


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