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


C# IContainer.Dispose方法代码示例

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


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

示例1: Start

        public void Start()
        {
            _container = ConfigureContainer().Build();
            HostFactory.Run(
                x =>
                    {
                        x.RunAsLocalService();

                        _overidedServiceConfiguration(x);

                        x.UseAutofacContainer(_container);
                        x.Service<JobsManager>(
                            s =>
                                {
                                    s.ConstructUsingAutofacContainer();
                                    s.WhenStarted(tc => tc.Start());
                                    s.WhenStopped(
                                        tc =>
                                            {
                                                tc.Stop();
                                                _container.Dispose();
                                            });

                                    ConfigureBackgroundJobs(s);
                                });

                        x.SetDescription(_serviceDescription);
                        x.SetDisplayName(_serviceDisplayName);
                        x.SetServiceName(_serviceName);
                        x.UseLog4Net();
                    });
        }
开发者ID:rewardle,项目名称:Rewardle.Polling,代码行数:32,代码来源:Poller.cs

示例2: StopService

 private static void StopService(IWeatherService srv, IContainer container)
 {
     try
     {
         srv.Stop();
         container.Dispose();
     }
     catch (Exception err)
     {
         EventLog.WriteEntry(Weatherservice, err.ToString(), EventLogEntryType.Error);
     }
 }
开发者ID:iiwaasnet,项目名称:weather,代码行数:12,代码来源:Program.cs

示例3: Main

        private static int Main(string[] args)
        {
            Console.WriteLine("This sample demostrates how to integrate Quartz, TopShelf and Autofac.");
            s_log.Info("Starting...");
            try
            {
                _container = ConfigureContainer(new ContainerBuilder()).Build();

                HostFactory.Run(conf =>
                {
                    conf.SetServiceName("AutofacExtras.Quartz.Sample");
                    conf.SetDisplayName("Quartz.Net integration for autofac");
                    conf.UseLog4Net();
                    conf.UseAutofacContainer(_container);

                    conf.Service<ServiceCore>(svc =>
                    {
                        svc.ConstructUsingAutofacContainer();
                        svc.WhenStarted(o => o.Start());
                        svc.WhenStopped(o =>
                        {
                            o.Stop();
                            _container.Dispose();
                        });
                        ConfigureBackgroundJobs(svc);
                    });
                });

                s_log.Info("Shutting down...");
                log4net.LogManager.Shutdown();
                return 0;
            }

            catch (Exception ex)
            {
                s_log.Fatal("Unhandled exception", ex);
                log4net.LogManager.Shutdown();
                return 1;
            }
        }
开发者ID:Boichu87,项目名称:Autofac.Extras.Quartz,代码行数:40,代码来源:Program.cs

示例4: Main

        static int Main(string[] args)
        {
            s_log.Info("Starting...");
            try
            {
                _container = ConfigureContainer(new ContainerBuilder()).Build();

                HostFactory.Run(conf =>
                {
                    conf.SetServiceName("VapoDataBus");
                    conf.SetDisplayName("Vaporize old DataBus folders");
                    conf.UseLog4Net();
                    conf.UseAutofacContainer(_container);

                    conf.Service<ServiceCore>(svc =>
                    {
                        svc.ConstructUsingAutofacContainer();
                        svc.WhenStarted(o => o.Start());
                        svc.WhenStopped(o =>
                        {
                            o.Stop();
                            _container.Dispose();
                        });
                        ConfigureBackgroundJobs(svc);
                    });
                });

                s_log.Info("Shutting down...");
                log4net.LogManager.Shutdown();
                return 0;
            }

            catch (Exception ex)
            {
                s_log.Fatal("Unhandled exception", ex);
                log4net.LogManager.Shutdown();
                return 1;
            }
        }
开发者ID:bradjolicoeur,项目名称:VapoDataBus,代码行数:39,代码来源:Program.cs

示例5: Main


//.........这里部分代码省略.........
                .OnSuccess((ep, m) =>
                {
                    Console.WriteLine("Get message {0} from {1}:{2}", m, ep.Address, ep.Port);
                    m.Sender.IpAddress = ep.Address;
                    _container.Resolve<HubblUsersService>().Add(m.Sender);
                }).OnException(
                    e =>
                    {
                        Console.WriteLine("Exception catched!");
                        Console.WriteLine("	" + e.Message);

                        throw e;
                    });
            ;

            router.Subscribe<TextMessage>()
                .OnSuccess((rp, m) =>
                {
                    var user = _container.Resolve<HubblUsersService>().Get(rp);
                    Console.WriteLine("{0}:{1}", user != null ? user.Title : Resources.UnknownUser, m.Text);
                }).OnException(
                    e =>
                    {
                        Console.WriteLine("Exception catched!");
                        Console.WriteLine("	" + e.Message);

                        throw e;
                    });
            ;

            router.Subscribe<AddCloudTrackMessage>()
                .OnSuccess((rp, m) =>
                {
                    Console.WriteLine("Cloud track request " + m.Track.Source);
                    var entry = _container.Resolve<IMusicPlayer>().QueueTrack(m.Sender, m.Track);
                    Console.WriteLine("added {0}", entry);
                }).OnException(
                    e =>
                    {
                        Console.WriteLine("Exception catched!");
                        Console.WriteLine("	" + e.Message);

                        throw e;
                    });

            router.Subscribe<SendFileMessage>()
                .OnSuccess((rp, m) =>
                {
                    Console.WriteLine("We got the file transfer! name:  " + m.Filename);
                    Console.WriteLine("	Trying to save...");

                    var fileStream = File.Create("files/", (int) m.StreamLength);

                    var bytesInStream = new byte[(int) m.Stream.Length];

                    m.Stream.Read(bytesInStream, 0, bytesInStream.Length);

                    fileStream.Write(bytesInStream, 0, bytesInStream.Length);
                }).OnException(
                    e =>
                    {
                        Console.WriteLine("Exception catched!");
                        Console.WriteLine("	" + e.Message);

                        throw e;
                    }).OnStart((m) =>
                    {
                        Console.WriteLine("We got the file transfer! on start!");
                        Console.WriteLine("	Trying to save...");

                    }

                );

            Task.Factory.StartNew(() => router.Start());

            Console.CancelKeyPress += ConsoleOnCancelKeyPress;
            _running = true;

            var users = _container.Resolve<IUsersService>();
            var player = _container.Resolve<IMusicPlayer>();

            while (_running)
            {
                Console.Write("hubl>: ");
                var commandLine = Regex.Split(Console.ReadLine() ?? string.Empty, "\\s");
                var commands = _container.Resolve<IEnumerable<ICommand>>();
                var cmd = commands.FirstOrDefault(m => m.Shortcuts.Contains(commandLine.FirstOrDefault()));
                if (cmd != null)
                {
                    if (cmd.Execute(commandLine.Skip(1).ToArray()))
                        break;
                }
                else Console.WriteLine(Resources.InvalidCommand);
            }
            Task.Factory.StartNew(() => router.Stop()).Wait();

            _container.Dispose();
            return 0;
        }
开发者ID:mesenev,项目名称:hubbl,代码行数:101,代码来源:Program.cs

示例6: Main


//.........这里部分代码省略.........
                            commerce5.ProcessOrder(orderInfo);
                            #endregion

                            break;
                        case "6":
                            #region module usage (Commerce6)
                            builder.RegisterType<Commerce6>();
                            builder.RegisterModule<ProcessorRegistrationModule>();

                            Container = builder.Build();

                            Commerce6 commerce6 = Container.Resolve<Commerce6>();

                            commerce6.ProcessOrder(orderInfo);
                            #endregion

                            break;
                        case "7":
                            #region one-to-many (Commerce7)
                            builder.RegisterType<Commerce7>();
                            builder.RegisterType<BillingProcessor>().As<IBillingProcessor>();
                            builder.RegisterType<CustomerProcessor>().As<ICustomerProcessor>();
                            builder.RegisterType<NotificationProcessor>().As<INotificationProcessor>();
                            builder.RegisterType<LoggingProcessor>().As<ILoggingProcessor>();
                            builder.RegisterType<ProcessorLocator>().As<IProcessorLocator>();
                            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                                .Where(t => t.Name.StartsWith("Plugin"))
                                .As<IPostOrderPlugin>();

                            Container = builder.Build();

                            Commerce7 commerce7 = Container.Resolve<Commerce7>();

                            commerce7.ProcessOrder(orderInfo);
                            #endregion

                            break;
                        case "8":
                            #region post-construction resolve & property injection (Commerce8)
                            builder.RegisterType<Commerce8>().PropertiesAutowired();
                            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                                .Where(t => t.Name.EndsWith("Processor"))
                                .As(t => t.GetInterfaces().FirstOrDefault(
                                    i => i.Name == "I" + t.Name));
                            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                                .Where(t => t.Name.StartsWith("Plugin"))
                                .As<IPostOrderPlugin>();
                            builder.RegisterType<ProcessorLocator>().As<IProcessorLocator>();

                            Container = builder.Build();

                            //Commerce8 commerce8 = new Commerce8();
                            Commerce8 commerce8 = Container.Resolve<Commerce8>();

                            commerce8.ProcessOrder(orderInfo);
                            #endregion

                            break;
                        case "9":
                            #region constructor finder (Commerce9)
                            builder.RegisterType<Commerce9>().WithParameters(new List<Autofac.Core.Parameter>() {
                            new NamedParameter("a", 1),
                            new NamedParameter("b", 1),
                            new NamedParameter("c", 1),
                            new NamedParameter("d", 1) });
                            #region fix
                            //builder.RegisterType<Commerce9>().WithParameters(new List<Autofac.Core.Parameter>() {
                            //    new NamedParameter("a", 1),
                            //    new NamedParameter("b", 1),
                            //    new NamedParameter("c", 1),
                            //    new NamedParameter("d", 1) }).FindConstructorsWith(new AwesomeConstructorFinder());
                            #endregion
                            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                                .Where(t => t.Name.EndsWith("Processor"))
                                .As(t => t.GetInterfaces().FirstOrDefault(
                                    i => i.Name == "I" + t.Name));
                            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                                .Where(t => t.Name.StartsWith("Plugin"))
                                .As<IPostOrderPlugin>();
                            builder.RegisterType<ProcessorLocator>().As<IProcessorLocator>();

                            Container = builder.Build();

                            Commerce9 commerce9 = Container.Resolve<Commerce9>();

                            commerce9.ProcessOrder(orderInfo);
                            #endregion

                            break;
                    }

                    Container.Dispose();

                    Console.WriteLine();
                    Console.WriteLine("Press 'Enter' for menu.");
                    Console.ReadLine();
                    Console.Clear();
                }
            }
        }
开发者ID:mncwabelindo,项目名称:amadizaynPhethini,代码行数:101,代码来源:Program.cs

示例7: ShutdownServices

        protected virtual async Task ShutdownServices(IContainer container)
        {
            Log.Info(m => m("Received OnAppDisposing event from OWIN container."));

            var taskRunner = container.Resolve<ITaskRunner>();
            var pendingTasks = taskRunner.PendingTasks;
            if (pendingTasks.Length > 0)
            {
                Log.Info(m => m("Waiting for {0} background tasks.", pendingTasks.Length));
                await Task.WhenAll(pendingTasks);
            }

            Log.Info(m => m("Disposing Autofac application container."));
            container.Dispose();
        }
开发者ID:jjchiw,项目名称:NuGet.Lucene,代码行数:15,代码来源:Startup.cs

示例8: CloseApplication

        private static void CloseApplication(IContainer container)
        {
            var context = container.Resolve<ApplicationContext>();

            container.Dispose();
            context.ExitThread();
        }
开发者ID:pvandervelde,项目名称:Apollo,代码行数:7,代码来源:DependencyInjection.cs

示例9: Main

        public static int Main(string[] args)
        {
            _container = CreateContainer ();
            var builder = new ContainerBuilder();
            builder.RegisterInstance(_container)
                .ExternallyOwned();
            builder.Update(_container);

            var networkSettings = _container.Resolve <NetworkSettings> ();
            networkSettings.TTL = 5;

            var router = _container.Resolve<INetworkMessageRouter> ();

            router.Subscribe<HelloMessage>()
                .OnSuccess((ep, m) =>
            {
                Console.WriteLine("Get message {0} from {1}:{2}", m, ep.Address, ep.Port);
                m.Sender.IpAddress = ep.Address;
                _container.Resolve<UsersService>().Add(m.Sender);
                router.PublishFor(new []{m.Sender.Id}, new EchoMessage(_container.Resolve<ISession>().CurrentUser)).First().Run();
            });

            router.Subscribe<EchoMessage>()
                .OnSuccess((ep, m) =>
                {
                    Console.WriteLine("Get message {0} from {1}:{2}", m, ep.Address, ep.Port);
                    m.Sender.IpAddress = ep.Address;
                    _container.Resolve<UsersService>().Add(m.Sender);
                });

            router.Subscribe<TextMessage>()
                .OnSuccess((rp, m) =>
                {
                    var user = _container.Resolve<UsersService>().Get(rp);
                    Console.WriteLine("{0}:{1}", user != null ? user.Title: Properties.Resources.UnknowUser, m.Text);
                });

            router.Subscribe<AddCloudTrackMessage> ()
                .OnSuccess((rp, m) =>
                    {
                        Console.WriteLine ("Cloud track request " + m.Track.Source);
                        _container.Resolve<IMusicPlayer> ().QueueTrack (m.Sender, m.Track);
                    });

            Task.Factory.StartNew(async () => await router.StartAsync());

            Console.CancelKeyPress += ConsoleOnCancelKeyPress;
            _runing = true;

            var users = _container.Resolve<UsersService> ();
            var player = _container.Resolve<IMusicPlayer> ();
            while (true) {
                router.PublishFor (users.GetUserIds (),
                    new HubMessagePlaylistWasUpdated () {
                        User = _container.Resolve<ISession> ().CurrentUser,
                        PlayingTrack = player.CurrentPlayedEntry,
                        Playlist = player.Playlist
                    });
                Thread.Sleep (100);
            }

            while (_runing)
            {
                Console.Write("hubl>: ");
                var commandLine = Regex.Split(Console.ReadLine() ?? string.Empty, "\\s");
                var commands = _container.Resolve<IEnumerable<ICommand>>();
                var cmd = commands.FirstOrDefault(m => m.Shortcuts.Contains(commandLine.FirstOrDefault()));
                if (cmd != null)
                {
                    if (cmd.Execute(commandLine.Skip(1).ToArray()))
                        break;
                }
                else Console.WriteLine(Properties.Resources.InvalidCommand);

            }
            Task.Factory.StartNew(() => router.StopAsync()).Wait();

            _container.Dispose();
            return 0;
        }
开发者ID:Grawl,项目名称:hubbl,代码行数:80,代码来源:Program.cs

示例10: RootSubscriptions

        private IEnumerable<IDisposable> RootSubscriptions(IContainer container)
        {
            yield return _configServiceLocator.OnRegisted(
                Observer.Create<IList<ComponentRegistrationValue>>(buffer => _eventAggregator.Publish(new RxAppServiceLocatorChangingEvent(buffer))));

            yield return _eventAggregator.GetEvent<OpenNewLifetimeScopeCommand>().Subscribe(command =>
            {
                _configServiceLocator.Upate(container.BeginLifetimeScope(command.Action));
                _logger.Info(string.Format("RxApp ServiceLocator setup success on thread {0}.", Thread.CurrentThread));
            });

            yield return _eventAggregator.GetEvent<RxAppServiceLocatorChangingEvent>().Subscribe(e =>
            {
                e.Update(container);
                _logger.Info(string.Format("RxApp ServiceLocator Registrations updated on thread {0}.", Thread.CurrentThread));

            });

            yield return Disposable.Create(() =>
            {
                container.Dispose();
                _logger.Info("Startup root container disposed");
            });
        }
开发者ID:jaohaohsuan,项目名称:ReactiveuiTrial,代码行数:24,代码来源:AppBootstrapper.cs


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