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


C# UnityContainer.AddNewExtension方法代码示例

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


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

示例1: Application_Start

        /// <summary>
        /// Starts the application.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
        protected void Application_Start(object sender, EventArgs e)
        {
            IConfigurationSource config = ConfigurationSourceFactory.Create();
            Logger.SetLogWriter(new LogWriterFactory(config).Create());
            ExceptionPolicy.SetExceptionManager(new ExceptionPolicyFactory(config).CreateManager());

            try
            {
                IUnityContainer container = new UnityContainer().LoadConfiguration();
                container.AddNewExtension<SecurityDependencyContainer>();
                container.AddNewExtension<WorflowDependencyContainer>();

                DependencyInjectionContainer = container;
                JsonConvert.DefaultSettings = () => new JsonSerializerSettings
                                                    {
                        Formatting = Formatting.None,
                        ContractResolver = new DiscretionalContractResolver(),
                        Converters = new JsonConverter[] { new JsonKnownTypeConverter() }
                    };
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "Default");
                if (rethrow)
                {
                    throw;
                }
            }
        }
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:34,代码来源:Global.asax.cs

示例2: ApiSetup

        static ApiSetup()
        {
            try
            {

                //Create
                Container = new UnityContainer();
                Locator = new UnityServiceLocator(Container);
                //Add entlib extensions
                Container.AddNewExtension<EnterpriseLibraryCoreExtension>();
#pragma warning disable 612,618
                Container.AddNewExtension<CachingBlockExtension>();
#pragma warning restore 612,618
                ServiceLocator.SetLocatorProvider(() => Locator);
                Container.LoadConfiguration("api");
                ApiDefaultConfig.DoDefaultRegistrations(Container);
                //NOTE: disabled for now
                //try
                //{
                //    ApiDefaultConfig.DoAutomaticConfiguration(Container);
                //    Initialization.Add(ApiSetupState.UnityAutoRegitrations, null);
                //}
                //catch (Exception e)
                //{
                //    Initialization.Add(ApiSetupState.UnityAutoRegitrations, new[] { e });
                //}
            }
            catch (Exception e)
            {
                Initialization.Add(ApiSetupState.UnityRegitrations, new[] { e });
                throw;
            }
            Initialization.Add(ApiSetupState.UnityRegitrations, null);
        }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:34,代码来源:ApiSetup.cs

示例3: Configure

 public static UnityContainer Configure()
 {
     var container = new UnityContainer();
     container.AddNewExtension<DataModule>();
     container.AddNewExtension<ProvidersModule>();
     container.AddNewExtension<ServiceModule>();
     container.AddNewExtension<AnalyticsModule>();
     return container;
 }
开发者ID:jpcgoodby,项目名称:Spread.Betting,代码行数:9,代码来源:UnityConfig.cs

示例4: Compose

    public static IDependencyInjectionContainer Compose()
    {
        var container = new UnityContainer();
        container.AddNewExtension<MvcSiteMapProviderContainerExtension>();
        container.AddNewExtension<MvcDemosContainerExtension>();

        GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);

        return new UnityDependencyInjectionContainer(container);
    }
开发者ID:sunilmunikar,项目名称:BestPractices,代码行数:10,代码来源:CompositionRoot.cs

示例5: RegisterComponents

        public static void RegisterComponents()
        {
			var container = new UnityContainer();
            container.AddNewExtension<QueriesExtension>();
            container.AddNewExtension<AuthenticationExtension>();
            container.AddNewExtension<CommandsExtension>();
            container.AddNewExtension<CommonServicesExtension>();
            container.AddNewExtension<WorkflowsExtension>();
            
            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }
开发者ID:Madster9000,项目名称:MF.Theater,代码行数:11,代码来源:UnityConfiguration.cs

示例6: Application_Start

 protected void Application_Start()
 {
     XmlConfigurator.Configure();
     var container = new UnityContainer();
     container.AddNewExtension<Bootstrapper>();
     GlobalConfiguration.Configure(WebApiConfig.Register);
 }
开发者ID:iburgos,项目名称:net-igeo-service,代码行数:7,代码来源:Global.asax.cs

示例7: Main

        public static void Main()
        {
            XmlConfigurator.Configure();
            var settings = new Settings();
            var container = new UnityContainer();

            container.AddNewExtension<Bootstrapper>();

            HostFactory.Run(c =>
            {
                c.UseUnityContainer(container);
                c.UseLog4Net();

                c.SetServiceName(settings.ServiceName);
                c.SetDisplayName(settings.ServiceDisplayName);
                c.SetDescription(settings.ServiceDescription);

                c.Service<ServiceStarter>(s =>
                {
                    s.ConstructUsingUnityContainer();
                    s.WhenStarted(pcs => pcs.Start());
                    s.WhenStopped(_ => { });
                });
            });
            System.Console.ReadKey();
        }
开发者ID:iburgos,项目名称:net-igeo-service,代码行数:26,代码来源:Program.cs

示例8: OnStartup

        protected override void OnStartup(StartupEventArgs e)
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<LazySupportExtension>();

            // Register grooveshark related stuff
            container.RegisterType<IGroovesharkClient, GroovesharkClientWrapper>(
                new ContainerControlledLifetimeManager(), 
                new InjectionMethod("Connect"));
            container.RegisterType<ISongProvider, GroovesharkSongProvider>(
                GroovesharkSongProvider.ProviderName, 
                new ContainerControlledLifetimeManager());
            container.RegisterType<ISongPlayer, GroovesharkSongPlayer>(
                GroovesharkSongProvider.ProviderName,
                new ContainerControlledLifetimeManager());

            // Register spotify/torshify related stuff
            container.RegisterType<ISongProvider, SpotifySongProvider>(
                SpotifySongProvider.ProviderName,
                new ContainerControlledLifetimeManager());
            container.RegisterType<ISongPlayer, TorshifySongPlayerClient>(
                SpotifySongProvider.ProviderName,
                new ContainerControlledLifetimeManager());
            container.RegisterType<ISpotifyImageProvider, TorshifyImageProvider>();

            // Aggregate provider that combines Grooveshark and Spotify players and providers
            container.RegisterType<ISongProvider, AggregateSongProvider>(new InjectionFactory(c =>
            {
                var a = new AggregateSongProvider(
                    c.Resolve<ISongProvider>(GroovesharkSongProvider.ProviderName),
                    c.Resolve<ISongProvider>(SpotifySongProvider.ProviderName));
                
                a.UnhandledException += (sender, args) =>
                {
                    Trace.WriteLine(args.Exception);
                    args.Handled = true;
                };

                return a;
            }));
            container.RegisterType<ISongPlayer, AggregateSongPlayer>(new InjectionFactory(c =>
            {
                return new AggregateSongPlayer(
                    c.Resolve<ISongPlayer>(GroovesharkSongProvider.ProviderName),
                    c.Resolve<ISongPlayer>(SpotifySongProvider.ProviderName));
            }));

            TorshifyServerProcessHandler torshifyServerProcess = new TorshifyServerProcessHandler();
            torshifyServerProcess.CloseServerTogetherWithClient = true;
            //torshifyServerProcess.Hidden = true;
            torshifyServerProcess.TorshifyServerLocation = Path.Combine(Environment.CurrentDirectory, "TRock.Music.Torshify.Server.exe");
            torshifyServerProcess.UserName = "<insert username>";
            torshifyServerProcess.Password = "<insert password>";
            torshifyServerProcess.Start();

            var provider = container.Resolve<ISongProvider>();

            MainWindow = container.Resolve<MainWindow>();
            MainWindow.Show();
        }
开发者ID:torshy,项目名称:TRock.Music,代码行数:60,代码来源:App.xaml.cs

示例9: Test

        public void Test()
        {
            using (var container = new UnityContainer())
            {
                container.RegisterType<ITestClass, TestClass>();
                container.AddNewExtension<LazyExtension>();

                var testClass1 = container.Resolve<Lazy<ITestClass>>();

                Assert.AreEqual(false, testClass1.IsValueCreated);
                Assert.AreEqual(0, TestClass.InstanceCount);

                Assert.AreEqual(5, testClass1.Value.HighFive());
                Assert.AreEqual(true, testClass1.IsValueCreated);
                Assert.AreEqual(1, TestClass.InstanceCount);

                var testClass2 = container.Resolve<Lazy<ITestClass>>();

                Assert.AreEqual(false, testClass2.IsValueCreated);
                Assert.AreEqual(1, TestClass.InstanceCount);

                Assert.AreEqual(5, testClass2.Value.HighFive());
                Assert.AreEqual(true, testClass2.IsValueCreated);
                Assert.AreEqual(2, TestClass.InstanceCount);
            }
        }
开发者ID:jcme,项目名称:Sample-MVC,代码行数:26,代码来源:LazyTest.cs

示例10: Setup

 public void Setup()
 {
     container = new UnityContainer();
     container.AddNewExtension<Interception>();
     container.RegisterTypeWithCallHandler<ArgumentNotNullHandler, ArgumentNotNullTest>();
     sample = container.Resolve<ArgumentNotNullTest>();
 }
开发者ID:isaacabraham,项目名称:Lydian.Unity.CallHandlers,代码行数:7,代码来源:ArgumentNotNullHandlerTests.cs

示例11: MassDisposable_Test

        public void MassDisposable_Test()
        {
            var container = new UnityContainer();
            container.AddNewExtension<DisposableStrategyExtension>();
            container.RegisterType<DisposableClass>(new DisposingTransientLifetimeManager());

            var sw = new Stopwatch();
            sw.Start();
            var objects = new List<DisposableClass>();
            for (int i = 0; i < 10000; i++)
            {
                objects.Add(container.Resolve<DisposableClass>());
            }

            sw.Stop();
            Context.WriteLine("Resolve: " + sw.Elapsed.ToString());

            sw.Restart();
            for (int i = 0; i < 10000; i++)
            {
                container.Teardown(objects[i]);
                Assert.IsTrue(objects[i].Disposed);
            }

            sw.Stop();
            Context.WriteLine("Teardown: " + sw.Elapsed.ToString());
        }
开发者ID:mskichu,项目名称:UnityExtension,代码行数:27,代码来源:DisposingTransientLifetimeManagerTests.cs

示例12: Compose

    public static IDependencyInjectionContainer Compose()
    {
        var container = new UnityContainer();
        container.AddNewExtension<MvcSiteMapProviderContainerExtension>();

        return new UnityDependencyInjectionContainer(container);
    }
开发者ID:at3158,项目名称:MvcSitemap2,代码行数:7,代码来源:CompositionRoot.cs

示例13: Combined_Test

        public void Combined_Test()
        {
            var container = new UnityContainer();
            container.AddNewExtension<DisposableStrategyExtension>();

            container.RegisterType<DisposableClass>("transient", new DisposingTransientLifetimeManager());
            container.RegisterType<DisposableClass>("shared", new DisposingSharedLifetimeManager());

            var transient1 = container.Resolve<DisposableClass>("transient");
            var transient2 = container.Resolve<DisposableClass>("transient");
            Assert.AreNotEqual(transient1, transient2);

            var shared1 = container.Resolve<DisposableClass>("shared");
            Assert.AreNotEqual(transient1, shared1);
            Assert.AreNotEqual(transient2, shared1);

            var shared2 = container.Resolve<DisposableClass>("shared");
            Assert.AreEqual(shared1, shared2);

            container.Teardown(transient1);
            Assert.IsTrue(transient1.Disposed);

            container.Teardown(shared2);
            Assert.IsFalse(shared2.Disposed);

            container.Teardown(shared1);
            Assert.IsTrue(shared1.Disposed);
        }
开发者ID:mskichu,项目名称:UnityExtension,代码行数:28,代码来源:CombinedTests.cs

示例14: UnityCanResolveEnumerableOfTypesRegisteredInUnityTest

        public void UnityCanResolveEnumerableOfTypesRegisteredInUnityTest()
        {
            // Setup
            var unityContainer = new UnityContainer();

            // Add composition support for unity
            unityContainer.AddNewExtension<LazySupportExtension>();

            Component1.InstanceCount = 0;
            Component2.InstanceCount = 0;

            unityContainer.RegisterType<IComponent, Component1>("component1");
            unityContainer.RegisterType<IComponent, Component2>("component2");
            unityContainer.RegisterType<IComponent, Component3>();

            var collectionOfLazyUnityComponents = unityContainer.Resolve<IEnumerable<IComponent>>();
            Assert.That(collectionOfLazyUnityComponents, Is.Not.Null);

            Assert.That(Component1.InstanceCount, Is.EqualTo(1));
            Assert.That(Component2.InstanceCount, Is.EqualTo(1));

            var list = new List<IComponent>(collectionOfLazyUnityComponents);
            Assert.That(list.Count, Is.EqualTo(3));

            Assert.That(list.OfType<Component1>().Count(), Is.EqualTo(1));
            Assert.That(list.OfType<Component2>().Count(), Is.EqualTo(1));
            Assert.That(list.OfType<Component3>().Count(), Is.EqualTo(1));
        }
开发者ID:pwlodek,项目名称:CodeGallery,代码行数:28,代码来源:LazySupportExtensionTests.cs

示例15: RegisterRepositoryTypes

        public static void RegisterRepositoryTypes(UnityContainer container)
        {
            /* Register types into the container */
            container.RegisterType<IDataService, DataService>();

            //container.RegisterType<IDataService, DummyDataService>();

            /* Register the Logger to be used by all calls from the container */
            container.RegisterType<LogHelper, LogHelper>(new ContainerControlledLifetimeManager());

            /* Register our data access helper to be used uniquely for each thread call from container */
            container.RegisterType<IDataAccessor, DataAccessor>(new PerThreadLifetimeManager());

            /* Register our matching rule and call handlers (AKA Aspects) */
            container.RegisterType<IMatchingRule, AllMatchingRule>(MatchingRule);
            container.RegisterType<ICallHandler, ExceptionCallHandler>(ExceptionCallHandler.Key);
            container.RegisterType<ICallHandler, UnitOfWorkCallHandler>(UnitOfWorkCallHandler.Key);
            container.RegisterType<ICallHandler, AuthenticationCallHandler>(AuthenticationCallHandler.Key);
            container.RegisterType<ICallHandler, CommandCallHandler>(CommandCallHandler.Key);
            container.RegisterType<ICallHandler, LogCallHandler>(LogCallHandler.Key);

            /* Create a new policy and reference the matching rule and call handler by name */
            container.AddNewExtension<Interception>();
            container.Configure<Interception>()
                .AddPolicy(PolicyName)
                .AddMatchingRule(MatchingRule)
                .AddCallHandler(ExceptionCallHandler.Key)
                .AddCallHandler(UnitOfWorkCallHandler.Key)
                //.AddCallHandler(LogCallHandler.Key)
                .AddCallHandler(AuthenticationCallHandler.Key)
                .AddCallHandler(CommandCallHandler.Key);

            /* Make IDataService interface elegible for interception */
            container.Configure<Interception>().SetInterceptorFor(typeof(IDataService), new TransparentProxyInterceptor());
        }
开发者ID:okcdg,项目名称:WCF-Unity,代码行数:35,代码来源:UnityConfig.cs


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