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


C# ILifetimeScope.Dispose方法代码示例

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


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

示例1: Init

        public void Init() {
            var clock = new StubClock();
            var appDataFolder = new StubAppDataFolder(clock);

            _controllerBuilder = new ControllerBuilder();
            _routeCollection = new RouteCollection();
            _modelBinderDictionary = new ModelBinderDictionary();
            _viewEngineCollection = new ViewEngineCollection { new WebFormViewEngine() };

            _container = OrchardStarter.CreateHostContainer(
                builder => {
                    builder.RegisterInstance(new StubShellSettingsLoader()).As<IShellSettingsManager>();
                    builder.RegisterType<RoutePublisher>().As<IRoutePublisher>();
                    builder.RegisterType<ModelBinderPublisher>().As<IModelBinderPublisher>();
                    builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
                    builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
                    builder.RegisterType<StubVirtualPathMonitor>().As<IVirtualPathMonitor>();
                    builder.RegisterInstance(appDataFolder).As<IAppDataFolder>();
                    builder.RegisterInstance(_controllerBuilder);
                    builder.RegisterInstance(_routeCollection);
                    builder.RegisterInstance(_modelBinderDictionary);
                    builder.RegisterInstance(_viewEngineCollection);
                    builder.RegisterAutoMocking()
                        .Ignore<IExtensionFolders>()
                        .Ignore<IRouteProvider>()
                        .Ignore<IHttpRouteProvider>()
                        .Ignore<IModelBinderProvider>()
                        .Ignore<IWorkContextEvents>()
                        .Ignore<IOwinMiddlewareProvider>();
                });
            _lifetime = _container.BeginLifetimeScope();

            _container.Mock<IContainerProvider>()
                .SetupGet(cp => cp.ApplicationContainer).Returns(_container);
            _container.Mock<IContainerProvider>()
                .SetupGet(cp => cp.RequestLifetime).Returns(_lifetime);
            _container.Mock<IContainerProvider>()
                .Setup(cp => cp.EndRequestLifetime()).Callback(() => _lifetime.Dispose());

            _container.Mock<IShellDescriptorManager>()
                .Setup(cp => cp.GetShellDescriptor()).Returns(default(ShellDescriptor));

            _container.Mock<IOrchardShellEvents>()
                .Setup(e => e.Activated());

            _container.Mock<IOrchardShellEvents>()
                .Setup(e => e.Terminating()).Callback(() => new object());
        }
开发者ID:SunRobin2015,项目名称:RobinWithOrchard,代码行数:48,代码来源:DefaultOrchardHostTests.cs

示例2: Init

        public void Init() {
            _controllerBuilder = new ControllerBuilder();
            _routeCollection = new RouteCollection();
            _modelBinderDictionary = new ModelBinderDictionary();
            _viewEngineCollection = new ViewEngineCollection { new WebFormViewEngine() };

            _container = OrchardStarter.CreateHostContainer(
                builder => {
                    builder.RegisterInstance(new StubShellSettingsLoader()).As<IShellSettingsManager>();
                    builder.RegisterType<StubContainerProvider>().As<IContainerProvider>().InstancePerLifetimeScope();
                    builder.RegisterType<RoutePublisher>().As<IRoutePublisher>();
                    builder.RegisterType<ModelBinderPublisher>().As<IModelBinderPublisher>();
                    builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
                    builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
                    builder.RegisterInstance(_controllerBuilder);
                    builder.RegisterInstance(_routeCollection);
                    builder.RegisterInstance(_modelBinderDictionary);
                    builder.RegisterInstance(_viewEngineCollection);
                    builder.RegisterAutoMocking()
                        .Ignore<IExtensionFolders>()
                        .Ignore<IRouteProvider>()
                        .Ignore<IModelBinderProvider>();
                });
            _lifetime = _container.BeginLifetimeScope();

            _container.Mock<IContainerProvider>()
                .SetupGet(cp => cp.ApplicationContainer).Returns(_container);
            _container.Mock<IContainerProvider>()
                .SetupGet(cp => cp.RequestLifetime).Returns(_lifetime);
            _container.Mock<IContainerProvider>()
                .Setup(cp => cp.EndRequestLifetime()).Callback(() => _lifetime.Dispose());

            _container.Mock<IShellDescriptorManager>()
                .Setup(cp => cp.GetShellDescriptor()).Returns(default(ShellDescriptor));

            var temp = Path.GetTempFileName();
            File.Delete(temp);
            Directory.CreateDirectory(temp);

            _container.Resolve<IAppDataFolder>()
                .SetBasePath(temp);

            var updater = new ContainerUpdater();
            updater.RegisterInstance(_container).SingleInstance();
            updater.Update(_lifetime);
        }
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:46,代码来源:DefaultOrchardHostTests.cs

示例3: Create

        public static WorkspaceViewModel Create(ILifetimeScope scope, IZetboxContext ctx)
        {
            if (scope == null) throw new ArgumentNullException("scope");
            if (ctx == null) throw new ArgumentNullException("ctx");

            var vmf = scope.Resolve<IViewModelFactory>();

            var ws = vmf.CreateViewModel<ObjectEditor.WorkspaceViewModel.Factory>().Invoke(ctx, null);
            ws.Closed += (s, e) => scope.Dispose();
            return ws;
        }
开发者ID:daszat,项目名称:zetbox,代码行数:11,代码来源:WorkspaceViewModel.cs

示例4: DisposeScope

      void DisposeScope(IJob job, ILifetimeScope lifetimeScope)
      {
          _logDebug(job, string.Format("Disposing Scope 0x{0:x} for Job 0x{1:x}",
              lifetimeScope != null ? lifetimeScope.GetHashCode() : 0,
              job != null ? job.GetHashCode() : 0));
 
          if (lifetimeScope != null)
              lifetimeScope.Dispose();
      }
开发者ID:rewardle,项目名称:Rewardle.Polling,代码行数:9,代码来源:PollerAutofacJobFactory.cs

示例5: DisposeScope

 private static void DisposeScope(IJob job, ILifetimeScope lifetimeScope)
 {
     if (s_log.IsDebugEnabled)
     {
         s_log.DebugFormat("Disposing Scope 0x{0:x} for Job 0x{1:x}",
             lifetimeScope != null ? lifetimeScope.GetHashCode() : 0,
             job != null ? job.GetHashCode() : 0);
     }
     if (lifetimeScope != null)
         lifetimeScope.Dispose();
 }
开发者ID:Boichu87,项目名称:Autofac.Extras.Quartz,代码行数:11,代码来源:AutofacJobFactory.cs

示例6: SetUp

 public void SetUp()
 {
     _fixture = new ModuleTestHarness();
     _fixture.ClearMessages();
     _lifetimeScope = _fixture.Container.BeginLifetimeScope();
     _lifetimeScope.Dispose();
     _lifetimeScopeBeginningMessage = _fixture.GetSingleMessageOrDefault<LifetimeScopeBeginningMessage>();
     _lifetimeScopeEndingMessage = _fixture.GetSingleMessageOrDefault<LifetimeScopeEndingMessage>();
 }
开发者ID:mustafatig,项目名称:whitebox,代码行数:9,代码来源:WhiteboxProfilingModuleTests.cs

示例7: Execute

        /// <summary>
        /// Executes the task
        /// </summary>
        public void Execute(ILifetimeScope scope = null, bool throwOnError = false)
        {
            this.IsRunning = true;

            scope = scope ?? EngineContext.Current.ContainerManager.Scope();
            var faulted = false;

            try
            {
                var task = this.CreateTask(scope);
                if (task != null)
                {
                    this.LastStartUtc = DateTime.UtcNow;

                    var scheduleTaskService = scope.Resolve<IScheduleTaskService>();
                    var scheduleTask = scheduleTaskService.GetTaskByType(this.Type);

                    if (scheduleTask != null)
                    {
                        //update appropriate datetime properties
                        scheduleTask.LastStartUtc = this.LastStartUtc;
                        scheduleTaskService.UpdateTask(scheduleTask);
                    }

                    //execute task
                    var ctx = new TaskExecutionContext()
                    {
                        LifetimeScope = scope,
                        CancellationToken = new CancellationTokenSource(TimeSpan.FromHours(6.0))	// TODO: make that somewhat configurable (AdminAreaSettings?)
                    };

                    task.Execute(ctx);
                    this.LastEndUtc = this.LastSuccessUtc = DateTime.UtcNow;
                    this.LastError = null;
                }
                else
                {
                    faulted = true;
                    this.LastError = "Could not create task instance";
                }
            }
            catch (Exception ex)
            {
                faulted = true;
                this.Enabled = !this.StopOnError;
                this.LastEndUtc = DateTime.UtcNow;
                this.LastError = ex.Message.Truncate(995, "...");

                //log error
                var logger = scope.Resolve<ILogger>();
                logger.Error(string.Format("Error while running the '{0}' schedule task. {1}", this.Name, ex.Message), ex);
                if (throwOnError)
                {
                    throw;
                }
            }
            finally
            {
                var scheduleTaskService = scope.Resolve<IScheduleTaskService>();
                var scheduleTask = scheduleTaskService.GetTaskByType(this.Type);

                if (scheduleTask != null)
                {
                    // update appropriate properties
                    scheduleTask.LastError = this.LastError;
                    scheduleTask.LastEndUtc = this.LastEndUtc;
                    if (!faulted)
                    {
                        scheduleTask.LastSuccessUtc = this.LastSuccessUtc;
                    }

                    scheduleTaskService.UpdateTask(scheduleTask);
                }

                scope.Dispose();

                this.IsRunning = false;
            }
        }
开发者ID:omidghorbani,项目名称:SmartStoreNET,代码行数:82,代码来源:Job.cs

示例8: WaitForCompletion

        /// <summary>
        /// Wait for all commands/events to be processed before allowing process to exit.
        /// </summary>
        /// <param name="container">The test IoC container.</param>
        private static void WaitForCompletion(ILifetimeScope container)
        {
            var statistics = container.Resolve<Statistics>();

            // Wait for statistics to stop capturing.
            while (statistics.Processing)
                Thread.Sleep(100);

            //Wait for all commands to be processed.
            WaitForCommandBusDrain(container);

            //Wait for all events to be processed.
            WaitForEventBusDrain(container);

            // Stop statistics collection.
            statistics.StopCapture();

            // Wait for all stores to complete any background processing.
            container.Resolve<SqlSnapshotStore>().Dispose();
            container.Resolve<SqlEventStore>().Dispose();
            container.Resolve<SqlSagaStore>().Dispose();

            // Dispose underlying IoC container.
            container.Dispose();
        }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:29,代码来源:Program.cs


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