Ejemplo n.º 1
0
        private IContainer CreateHostContainer()
        {
            var hostContainer = OrchardStarter.CreateHostContainer(ContainerRegistrations);
            var host          = hostContainer.Resolve <IOrchardHost>();

            host.Initialize();
            return(hostContainer);
        }
Ejemplo n.º 2
0
        protected void Application_Start()
        {
            _hostContainer = OrchardStarter.CreateHostContainer(MvcSingletons);
            _host          = _hostContainer.Resolve <IOrchardHost>();
            _host.Initialize();

            var route = RouteTable.Routes.MapRoute("foo", "hello-world", new { controller = "Home", action = "Index" });

            route.RouteHandler = new HelloYetAgainHandler();
        }
        public void MostRecentlyRegisteredServiceReturnsFromSingularResolve()
        {
            var container = OrchardStarter.CreateHostContainer(builder => {
                builder.RegisterType <Component1>().As <IServiceA>();
                builder.RegisterType <Component2>().As <IServiceA>();
            });
            var service = container.Resolve <IServiceA>();

            Assert.That(service, Is.Not.Null);
            Assert.That(service, Is.TypeOf <Component2>());
        }
Ejemplo n.º 4
0
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
            _container = OrchardStarter.CreateHostContainer(MvcSingletons);
            _host      = _container.Resolve <IOrchardHost>();

            _host.Initialize();

            // initialize shells to speed up the first dynamic query
            _host.BeginRequest();
            _host.EndRequest();
        }
        public void ContainerResolvesServicesInSameOrderTheyAreRegistered()
        {
            var container = OrchardStarter.CreateHostContainer(builder => {
                builder.RegisterType <Component1>().As <IServiceA>();
                builder.RegisterType <Component2>().As <IServiceA>();
            });
            var services = container.Resolve <IEnumerable <IServiceA> >();

            Assert.That(services.Count(), Is.EqualTo(2));
            Assert.That(services.First(), Is.TypeOf <Component1>());
            Assert.That(services.Last(), Is.TypeOf <Component2>());
        }
        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());
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AgentBase"/> class.
 /// </summary>
 public AgentBase()
 {
     this.HostContainer    = OrchardStarter.CreateHostContainer(this.ContainerRegistrations);
     this.ContainerManager = this.HostContainer.Resolve <IContainerManager>();
 }
Ejemplo n.º 8
0
 public void Init()
 {
     _hostContainer = OrchardStarter.CreateHostContainer(builder => {
         builder.RegisterType <Alpha>().InstancePerDependency();
     });
 }
Ejemplo n.º 9
0
        public static IContainer CreateHostContainer(IOrchardAppHost appHost, AppHostSettings settings, AppHostRegistrations registrations)
        {
            return(OrchardStarter.CreateHostContainer(builder =>
            {
                builder.RegisterType <AppHostEnvironment>().As <IHostEnvironment>().SingleInstance();

                // Needed also for shells, separately.
                RegisterAppDataFolderRoot(builder, settings.AppDataFolderPath).SingleInstance();

                RegisterVolatileProvider <AppHostVirtualPathMonitor, IVirtualPathMonitor>(builder);
                RegisterVolatileProvider <AppHostVirtualPathProvider, IVirtualPathProvider>(builder);
                RegisterVolatileProvider <AppHostWebSiteFolder, IWebSiteFolder>(builder);

                var shellRegistrations = new ShellContainerRegistrations
                {
                    Registrations = shellBuilder =>
                    {
                        // Despite imported assemblies being handled these registrations are necessary, because they are needed too early.
                        // Adding them as normal services, even with OrchardSuppressDependency, wouldn't work.

                        RegisterAppDataFolderRoot(shellBuilder, settings.AppDataFolderPath).InstancePerMatchingLifetimeScope("shell");

                        RegisterVolatileProviderForShell <AppHostVirtualPathMonitor, IVirtualPathMonitor>(shellBuilder);
                        RegisterVolatileProviderForShell <AppHostVirtualPathProvider, IVirtualPathProvider>(shellBuilder);
                        RegisterVolatileProviderForShell <AppHostWebSiteFolder, IWebSiteFolder>(shellBuilder);

                        if (registrations.ShellRegistrations != null)
                        {
                            registrations.ShellRegistrations(shellBuilder);
                        }
                    }
                };
                builder.RegisterInstance(shellRegistrations).As <IShellContainerRegistrations>();

                // Handling imported assemblies.
                if (settings.ImportedExtensions != null && settings.ImportedExtensions.Any())
                {
                    builder.RegisterType <ImportedExtensionsProvider>().As <IExtensionFolders, IExtensionLoader>().SingleInstance()
                    .WithParameter(new NamedParameter("extensions", settings.ImportedExtensions));
                }

                // Configuring extension loading.
                builder.RegisterType <ExtensionPathsProvider>().As <IExtensionPathsProvider>().SingleInstance()
                .WithParameter(new NamedParameter("hostSettings", settings));
                builder.RegisterType <AppHostExtensionFolders>().As <IExtensionFolders>().SingleInstance();
                builder.RegisterType <AppHostCoreExtensionLoader>().As <IExtensionLoader>().SingleInstance();
                builder.RegisterType <AppHostRawThemeExtensionLoader>().As <IExtensionLoader>().SingleInstance();

                if (settings.DisableConfiguratonCaches)
                {
                    builder.RegisterModule <ConfigurationCacheDisablingModule>();
                }

                if (settings.DisableExtensionMonitoring)
                {
                    builder.RegisterModule <ExtensionMonitoringDisablingModule>();
                }

                // Either we register MVC singletons or we need at least a new IOrchardShell implementation.
                builder.Register(ctx => RouteTable.Routes).SingleInstance();
                builder.Register(ctx => ModelBinders.Binders).SingleInstance();
                builder.Register(ctx => ViewEngines.Engines).SingleInstance();

                builder.RegisterType <LoggerService>().As <ILoggerService>().SingleInstance();

                builder.RegisterInstance(appHost).As <IOrchardAppHost>().ExternallyOwned();

                if (registrations.HostRegistrations != null)
                {
                    registrations.HostRegistrations(builder);
                }
            }));
        }