Task ISubSystem.Start()
        {
            return(Task.Factory.StartNew(() => {
                var settings = StoryTellerEnvironment.Get <SerenityEnvironment>();
                WebDriverSettings.Import(settings);

                FubuMvcPackageFacility.PhysicalRootPath = _settings.PhysicalPath;
                _runtime = _runtimeSource();


                var browserLifecycle = WebDriverSettings.GetBrowserLifecyle(ChooseBrowserType());
                _hosting = _settings.RootUrl.IsEmpty() ? (ISerenityHosting) new KatanaHosting() : new ExternalHosting();

                _application = _hosting.Start(_settings, _runtime, browserLifecycle);
                _applicationAlterations.Each(x => x(_application));

                _binding = _application.Services.GetInstance <BindingRegistry>();
                _bindingRegistrations.Each(x => x(_binding));

                configureApplication(_application, _binding);

                _contextualProviders = _runtime.Factory.GetAll <IContextualInfoProvider>();


                _runtime.Facility.Register(typeof(IApplicationUnderTest), ObjectDef.ForValue(_application));
                _runtime.Facility.Register(typeof(IRemoteSubsystems), ObjectDef.ForValue(this));
            }));
        }
Exemple #2
0
        public void Configure(BehaviorGraph graph)
        {
            var settings = graph.Settings.Get <ValidationSettings>();
            var query    = new RemoteRuleQuery(settings.Filters);

            graph.Services.SetServiceIfNone(typeof(IRemoteRuleQuery), ObjectDef.ForValue(query));
        }
Exemple #3
0
        private void addStringConversions(DisplayConversionRegistry conversions)
        {
            var registry = new ServiceRegistry();

            registry.AddService(typeof(DisplayConversionRegistry), ObjectDef.ForValue(conversions));
            _configuration.Add(registry);
        }
Exemple #4
0
        private void bakeBehaviorGraphIntoContainer(BehaviorGraph graph, IContainerFacility containerFacility)
        {
            graph.As <IRegisterable>().Register(_registry.Value.DiagnosticLevel, containerFacility.Register);

            // Important to register itself
            containerFacility.Register(typeof(IContainerFacility), ObjectDef.ForValue(containerFacility));
        }
Exemple #5
0
        public FubuRuntime Bootstrap()
        {
            SetupNamingStrategyForHttpHeaders();

            _fubuFacility = new FubuMvcPackageFacility();

            IServiceFactory factory = null;
            BehaviorGraph   graph   = null;

            // TODO -- I think Bottles probably needs to enforce a "tell me the paths"
            // step maybe
            PackageRegistry.GetApplicationDirectory = FubuMvcPackageFacility.GetApplicationPath;
            BottleFiles.ContentFolder  = FubuMvcPackageFacility.FubuContentFolder;
            BottleFiles.PackagesFolder = FileSystem.Combine("bin", FubuMvcPackageFacility.FubuPackagesFolder);

            IList <RouteBase> routes = null;

            PackageRegistry.LoadPackages(x => {
                x.Facility(_fubuFacility);
                _packagingDirectives.Each(d => d(x));

                x.Bootstrap(log => {
                    // container facility has to be spun up here
                    var containerFacility = _facility.Value;

                    // Need to do this to make the provenance for bottles come out right
                    _registry.Value.Config.Seal();

                    applyFubuExtensionsFromPackages();

                    graph = buildBehaviorGraph();

                    bakeBehaviorGraphIntoContainer(graph, containerFacility);

                    // factory HAS to be spun up here.
                    factory = containerFacility.BuildFactory();

                    routes = buildRoutes(factory, graph);
                    routes.Each(r => RouteTable.Routes.Add(r));
                    containerFacility.Register(typeof(FubuRouteTable), ObjectDef.ForValue(new FubuRouteTable {
                        Routes = routes
                    }));

                    return(factory.GetAll <IActivator>());
                });
            });

            FubuMvcPackageFacility.Restarted = DateTime.Now;

            PackageRegistry.AssertNoFailures(
                () => { throw new FubuException(0, FubuApplicationDescriber.WriteDescription()); });


            var runtime = new FubuRuntime(factory, _facility.Value, routes);

            _facility.Value.Register(typeof(FubuRuntime), ObjectDef.ForValue(runtime));

            return(runtime);
        }
Exemple #6
0
        public void Configure(BehaviorGraph graph)
        {
            var settings = graph.Settings.Get <ConfigurationSettings>();

            var registry = settings.BuildRegistry(graph);

            graph.Services.AddService(typeof(Registry), ObjectDef.ForValue(registry));
        }
        private void addCaching(BehaviorChain chain)
        {
            var cacheNode = new OutputCachingNode {
                ETagCache   = ObjectDef.ForValue(_assetCache),
                OutputCache = ObjectDef.ForValue(_assetCache)
            };

            chain.AddToEnd(cacheNode);
        }
Exemple #8
0
        public void simple_ObjectDef_by_value()
        {
            var service = new SimpleService();

            var container = ContainerFacilitySource.New(x => {
                x.Register(typeof(IService), ObjectDef.ForValue(service));
            });

            container.Get <IService>().ShouldBeTheSameAs(service);
        }
        public void Activate(IEnumerable <IPackageInfo> packages, IPackageLog log)
        {
            var library = new TagProfileLibrary();

            _conventions.Each(library.ImportRegistry);

            library.ImportRegistry(new DefaultHtmlConventions());
            library.Seal();

            _container.Register(typeof(TagProfileLibrary), ObjectDef.ForValue(library));
        }
        public void Configure(BehaviorGraph graph)
        {
            var settings = graph.Settings.Get <TransportSettings>();

            settings.SettingTypes.Each(settingType => {
                var settingObject = InMemoryTransport.ToInMemory(settingType);

                graph.Services.AddService(settingType, ObjectDef.ForValue(settingObject));
                graph.Services.Clear(typeof(ITransport));
            });
        }
Exemple #11
0
        public AutofacContainerFacility(IComponentContext context)
        {
            _context = context;
            _module  = new AutofacFubuModule();

            _register = (serviceType, def) =>
            {
                bool isSingleton = (ServiceRegistry.ShouldBeSingleton(serviceType) || ServiceRegistry.ShouldBeSingleton(def.Type) || def.IsSingleton);
                _module.AddRegistration(serviceType, def, isSingleton);
            };

            _register(typeof(IServiceFactory), ObjectDef.ForValue(this));
        }
        public void Configure(BehaviorGraph graph)
        {
            var rules   = graph.Settings.Get <AccessorRules>();
            var library = graph.Settings.Get <HtmlConventionLibrary>();

            library.Import(new DefaultHtmlConventions().Library);

            var visitor = new Visitor(rules);

            library.For <ElementRequest>().AcceptVisitor(visitor);

            graph.Services.SetServiceIfNone(typeof(HtmlConventionLibrary), ObjectDef.ForValue(library));
        }
Exemple #13
0
        /// <summary>
        /// Adds an authorization rule based on membership in a given role
        /// on the principal
        /// </summary>
        /// <param name="roleName"></param>
        /// <returns></returns>
        public AllowRole AddRole(string roleName)
        {
            if (AllowedRoles().Contains(roleName))
            {
                return(null);
            }

            var allow = new AllowRole(roleName);

            _policies.Add(ObjectDef.ForValue(allow));

            return(allow);
        }
Exemple #14
0
        public PollingServicesRegistry()
        {
            // NEED MORE.
            SetServiceIfNone <ITimer, DefaultTimer>();
            AddService <IDeactivator, PollingJobDeactivator>();
            SetServiceIfNone <IPollingJobLogger, PollingJobLogger>();

            var def = ObjectDef.ForType <PollingJobs>();

            def.IsSingleton = true;
            SetServiceIfNone(typeof(IPollingJobs), def);

            SetServiceIfNone(typeof(PollingJobLatch), ObjectDef.ForValue(new PollingJobLatch()).AsSingleton());
        }
Exemple #15
0
        public void Modify(ConnegGraph graph, BehaviorGraph behaviorGraph)
        {
            graph.OutputNodesFor <T>().Each(node => _modifications.Each(x => x(node)));

            if (_projection.IsValueCreated)
            {
                behaviorGraph.Services.SetServiceIfNone(typeof(IProjection <T>), ObjectDef.ForValue(_projection.Value));
            }

            if (_links.IsValueCreated)
            {
                behaviorGraph.Services.SetServiceIfNone(typeof(ILinkSource <T>), ObjectDef.ForValue(_links.Value));
            }
        }
Exemple #16
0
        public static void RegisterPartials(this FubuRegistry registry,
                                            Action <IPartialViewTypeRegistrationExpression> registration)
        {
            registry.Configure(x =>
            {
                var services = x.Services;

                services.SetServiceIfNone(typeof(IPartialViewTypeRegistry), ObjectDef.ForValue(new PartialViewTypeRegistry()));
                var partialRegistry = services.FindAllValues <IPartialViewTypeRegistry>().FirstOrDefault();

                var expression = new PartialViewTypeRegistrationExpression(partialRegistry);
                registration(expression);
            });
        }
Exemple #17
0
        public void build_object_def()
        {
            MockFor <IViewToken>().Stub(x => x.ViewModel).Return(typeof(SomeResource));

            var viewFactoryDef = ObjectDef.ForValue(MockRepository.GenerateMock <IViewFactory>());

            MockFor <IViewToken>().Stub(x => x.ToViewFactoryObjectDef())
            .Return(viewFactoryDef);

            ClassUnderTest.As <IContainerModel>()
            .ToObjectDef()
            .FindDependencyDefinitionFor <IMediaWriter <SomeResource> >()
            .FindDependencyDefinitionFor <IViewFactory>()
            .ShouldBeTheSameAs(viewFactoryDef);
        }
Exemple #18
0
        public void add_view_with_condition()
        {
            var node      = new OutputNode(typeof(Address));
            var viewToken = MockRepository.GenerateMock <IViewToken>();

            viewToken.Stub(x => x.ViewModel).Return(typeof(Address));
            viewToken.Stub(x => x.ToViewFactoryObjectDef()).Return(
                ObjectDef.ForValue(MockRepository.GenerateMock <IViewFactory>()));

            var viewNode = node.AddView(viewToken, typeof(FakeConditional));

            viewNode.As <IContainerModel>().ToObjectDef()
            .FindDependencyDefinitionFor <IConditional>()
            .Type
            .ShouldEqual(typeof(FakeConditional));
        }
Exemple #19
0
        public void Activate(IEnumerable <IPackageInfo> packages, IPackageLog log)
        {
            var list = new List <string>();

            log.Trace("Setting up the {0} with directories", typeof(XmlDirectoryLocalizationStorage).Name);

            list.Add(FubuMvcPackageFacility.GetApplicationPath());

            packages.Each(pak => pak.ForFolder(BottleFiles.WebContentFolder, list.Add));

            var storage = new XmlDirectoryLocalizationStorage(list);

            _facility.Register(typeof(ILocalizationStorage), ObjectDef.ForValue(storage));

            _facility.Get <SpinUpLocalizationCaches>().Activate(packages, log);
        }
Exemple #20
0
        public void Configure <T>(Action <T> configure) where T : class, new()
        {
            var list    = _services[typeof(T)];
            T   @object = null;

            list.FirstOrDefault().IfNotNull(x => @object = x.Value as T);

            if (@object == null)
            {
                list.Clear();
                @object = new T();
                list.Add(ObjectDef.ForValue(@object));
            }

            configure(@object);
        }
Exemple #21
0
        public void ObjectDef_with_one_explicit_dependency_defined_by_value()
        {
            var container = ContainerFacilitySource.New(x =>
            {
                x.Register(typeof(IService), ObjectDef.ForType <SimpleService>());

                var objectDef = ObjectDef.ForType <GuyWithService>();
                objectDef.DependencyByType <IService>(ObjectDef.ForValue(new DifferentService()));

                x.Register(typeof(GuyWithService), objectDef);
            });

            // The default IService is SimpleService, but the default ObjectDef (first one) explicitly
            // set up its IService dependency to be a "DifferentService"
            container.Get <GuyWithService>().Service.ShouldBeOfType <DifferentService>();
        }
Exemple #22
0
        Task ISubSystem.Start()
        {
            return(Task.Factory.StartNew(() =>
            {
                FubuMvcPackageFacility.PhysicalRootPath = _settings.PhysicalPath;
                _runtime = _runtimeSource();

                var browserLifecycle = WebDriverSettings.GetBrowserLifecyle(ChooseBrowserType());
                SetupApplicationHost();

                _application = _hosting.Start(_settings, _runtime, browserLifecycle);
                _applicationAlterations.Each(x => x(_application));

                _runtime.Facility.Register(typeof(IApplicationUnderTest), ObjectDef.ForValue(_application));
                _runtime.Facility.Register(typeof(IRemoteSubsystems), ObjectDef.ForValue(this));
            }));
        }
Exemple #23
0
        private void startAtPort(string rootDirectory, FubuRuntime runtime)
        {
            _baseAddress   = "http://localhost:" + _port;
            _configuration = new HttpSelfHostConfiguration(_baseAddress);

            FubuMvcPackageFacility.PhysicalRootPath = rootDirectory;

            _server = new HttpSelfHostServer(_configuration, new SelfHostHttpMessageHandler(runtime)
            {
                Verbose = Verbose
            });

            runtime.Facility.Register(typeof(HttpSelfHostConfiguration), ObjectDef.ForValue(_configuration));

            Console.WriteLine("Starting to listen for requests at " + _configuration.BaseAddress);

            _server.OpenAsync().Wait();
        }
        public InProcessApplicationUnderTest(ApplicationSettings settings)
        {
            _settings = settings;

            _runtime = new Lazy <FubuRuntime>(() =>
            {
                FubuMvcPackageFacility.PhysicalRootPath = settings.GetApplicationFolder();

                // TODO -- add some diagnostics here
                var runtime = new TSystem().BuildApplication().Bootstrap();
                runtime.Facility.Register(typeof(ICurrentHttpRequest), ObjectDef.ForValue(new StubCurrentHttpRequest()
                {
                    ApplicationRoot = "http://localhost:" + settings.Port
                }));

                return(runtime);
            });

            _urls = new Lazy <IUrlRegistry>(() => _runtime.Value.Facility.Get <IUrlRegistry>());

            _browser = new Lazy <IWebDriver>(() =>
            {
                var reset = startListener(settings, _runtime.Value);

                _disposals.Add(() =>
                {
                    _listener.Stop();
                    _listener.SafeDispose();

                    _listeningThread.Join(3000);
                });

                reset.WaitOne();

                var browser = WebDriverSettings.DriverBuilder()();
                _disposals.Add(browser.Close);

                return(browser);
            });
        }
Exemple #25
0
        void IFubuRegistryExtension.Configure(FubuRegistry registry)
        {
            var graph    = new HandlerGraph();
            var allCalls = allSources().SelectMany(x => x.FindCalls()).Distinct();

            graph.Add(allCalls);

            graph.ApplyPolicies(_localPolicies);

            registry.AlterSettings <HandlerGraph>(x => x.Import(graph));

            registry.AlterSettings <ChannelGraph>(channels => {
                _channelAlterations.Each(x => x(channels));
            });

            registry.Configure(behaviorGraph => {
                var channels = behaviorGraph.Settings.Get <ChannelGraph>();
                behaviorGraph.Services.Clear(typeof(ChannelGraph));
                behaviorGraph.Services.AddService(typeof(ChannelGraph), ObjectDef.ForValue(channels).AsSingleton());
            });

            _alterations.Each(x => x(registry));
        }
Exemple #26
0
 public void FailureHandler(IAuthorizationFailureHandler handler)
 {
     _failure = ObjectDef.ForValue(handler);
 }
        public void Configure(BehaviorGraph graph)
        {
            var scheduledJobs = graph.Settings.Get <ScheduledJobGraph>();

            scheduledJobs.Jobs.Each(x => {
                graph.Services.SetServiceIfNone(typeof(IScheduledJob <>).MakeGenericType(x.JobType), ObjectDef.ForValue(x));
            });
        }
 public RegisterAllSettings(BehaviorGraph graph)
 {
     graph.Settings.ForAllSettings((type, o) => SetServiceIfNone(type, ObjectDef.ForValue(o)));
 }
Exemple #29
0
 public void Register(ServiceGraph graph)
 {
     graph.SetServiceIfNone(typeof(T), ObjectDef.ForValue(_task.Result));
 }
Exemple #30
0
        public CoreServiceRegistry()
        {
            AddService<IDeactivator, MiddlewareDeactivator>();

            SetServiceIfNone<IRequestCompletion, RequestCompletion>();

            SetServiceIfNone<IRequestData, FubuMvcRequestData>();
            SetServiceIfNone(typeof(AppReloaded), ObjectDef.ForValue(new AppReloaded()));

            var stringifier = new Stringifier();
            SetServiceIfNone(stringifier);
            SetServiceIfNone<IStringifier>(stringifier); // Hack!
            AddService(new TypeDescriptorCache());

            SetServiceIfNone<IConditionalService, ConditionalService>();
            SetServiceIfNone<IOutputWriter, OutputWriter>();

            SetServiceIfNone<IUrlRegistry, UrlRegistry>();
            SetServiceIfNone<IChainUrlResolver, ChainUrlResolver>();
            SetServiceIfNone<IUrlTemplatePattern, NulloUrlTemplate>();

            SetServiceIfNone<IFlash, FlashProvider>();
            SetServiceIfNone<IRequestDataProvider, RequestDataProvider>();

            SetServiceIfNone<IFubuRequest, FubuRequest>();
            SetServiceIfNone<IPartialFactory, PartialFactory>();
            SetServiceIfNone<IContinuationProcessor, ContinuationProcessor>();

            SetServiceIfNone<IDisplayFormatter, DisplayFormatter>();
            SetServiceIfNone<IChainResolver, ChainResolutionCache>();

            SetServiceIfNone<IEndpointService, EndpointService>();


            SetServiceIfNone<ITypeDescriptorCache, TypeDescriptorCache>();

            SetServiceIfNone<ISessionState, SimpleSessionState>();



            SetServiceIfNone<IFubuRequestContext, FubuRequestContext>();
            SetServiceIfNone<IFileSystem, FileSystem>();


            SetServiceIfNone<IObjectConverter, ObjectConverter>();

            SetServiceIfNone<ISmartRequest, FubuSmartRequest>();
            SetServiceIfNone<IResourceNotFoundHandler, DefaultResourceNotFoundHandler>();


            SetServiceIfNone<ILogger, Logger>();
            AddService<ILogModifier, LogRecordModifier>();

            SetServiceIfNone<IClock, Clock>(x => x.IsSingleton = true);
            SetServiceIfNone<ITimeZoneContext, MachineTimeZoneContext>();
            SetServiceIfNone<ISystemTime, SystemTime>();

            SetServiceIfNone<IExceptionHandlingObserver, ExceptionHandlingObserver>();
            SetServiceIfNone<IAsyncCoordinator, AsyncCoordinator>();

            SetServiceIfNone<IPartialInvoker, PartialInvoker>();

            AddService<IHttpContentEncoding, GZipHttpContentEncoding>();
            AddService<IHttpContentEncoding, DeflateHttpContentEncoding>();
            SetServiceIfNone<IHttpContentEncoders, HttpContentEncoders>();

            SetServiceIfNone<ICookies, Cookies>();

            if (FubuMode.InDevelopment())
            {
                SetServiceIfNone<IAssetTagBuilder, DevelopmentModeAssetTagBuilder>();
            }
            else
            {
                SetServiceIfNone<IAssetTagBuilder, AssetTagBuilder>();
            }

            SetServiceIfNone<IJavascriptRouteData, JavascriptRouteData>();

            SetServiceIfNone(typeof(IValues<>), typeof(SimpleValues<>));
            SetServiceIfNone(typeof(IValueSource<>), typeof(ValueSource<>));

            SetServiceIfNone<IProjectionRunner, ProjectionRunner>();
            SetServiceIfNone(typeof(IProjectionRunner<>), typeof(ProjectionRunner<>));
            SetServiceIfNone<IProjectionRunner, ProjectionRunner>();
            SetServiceIfNone(typeof(IProjectionRunner<>), typeof(ProjectionRunner<>));

            SetServiceIfNone<ISettingsProvider, SettingsProvider>();
            AddService<ISettingsSource>(new AppSettingsSettingSource(SettingCategory.environment));

            ReplaceService<TemplateGraph, TemplateGraph>();

            SetServiceIfNone<IAssetFinder, AssetFinderCache>();
        }