protected void Application_Start() { XmlConfigurator.Configure(); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); ModelBinders.Binders.DefaultBinder = new SharpModelBinder(); ModelValidatorProviders.Providers.Add(new ClientDataTypeModelValidatorProvider()); this.InitializeServiceLocator(); AreaRegistration.RegisterAllAreas(); RouteRegistrar.RegisterRoutesTo(RouteTable.Routes); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); }
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context) { base.ConfigureRequestContainer(container, context); // create a singleton instance which will be reused for all calls in current request var ipb = new Router(); container.Register <ICommandSender, Router>(ipb); container.Register <IHandlerRegistrar, Router>(ipb); container.Register <IEventSerializer, EventSerializer>(new EventSerializer()); container.Register <IEventSourceFactory, EventSourceFactory>(); container.Register <ISettingsService, SettingsService>(); container.Register <NeuronCommandHandlers>(); var ticl = new TinyIoCServiceLocator(container); container.Register <IServiceProvider, TinyIoCServiceLocator>(ticl); var registrar = new RouteRegistrar(ticl); registrar.Register(typeof(NeuronCommandHandlers)); // Here we register our user mapper as a per-request singleton. // As this is now per-request we could inject a request scoped // database "context" or other request scoped services. ((TinyIoCServiceLocator)container.Resolve <IServiceProvider>()).SetRequestContainer(container); }
public void RouteTest_DefaultRoute() { var routes = new RouteCollection(); RouteRegistrar.RegisterAll(routes); routes.ShouldMap("~/").To <RootController>(x => x.Index()); }
public void RouteTest_AdminTournamentDefaultPageNew() { var routes = new RouteCollection(); RouteRegistrar.RegisterAll(routes); routes.ShouldMap("~/Admin/Tournament/14").To <TournamentAdminController>(x => x.AdminIndex(14)); }
public When_registering_handlers() { _locator = new TestServiceLocator(); var register = new RouteRegistrar(_locator); register.Register(GetType()); }
public void RouteTest_Error404() { var routes = new RouteCollection(); RouteRegistrar.RegisterAll(routes); routes.ShouldMap("~/Error/Error404").To <ErrorController>(x => x.Error404()); }
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context) { base.ConfigureRequestContainer(container, context); container.Register <ISettingsService, SettingsService>(); container.Register <INeuronRepository, NeuronRepository>(); container.Register <ITerminalRepository, TerminalRepository>(); container.Register <IRepository <Domain.Model.Settings>, SettingsRepository>(); container.Register <INotificationLogClient, StandardNotificationLogClient>(); var ipb = new Router(); container.Register <ICommandSender, Router>(ipb); container.Register <IHandlerRegistrar, Router>(ipb); container.Register <GraphCommandHandlers>(); var ticl = new TinyIoCServiceLocator(container); container.Register <IServiceProvider, TinyIoCServiceLocator>(ticl); var registrar = new RouteRegistrar(ticl); registrar.Register(typeof(GraphCommandHandlers)); // As this is now per-request we could inject a request scoped // database "context" or other request scoped services. ((TinyIoCServiceLocator)container.Resolve <IServiceProvider>()).SetRequestContainer(container); }
public void RouteTest_AdminMain() { var routes = new RouteCollection(); RouteRegistrar.RegisterAll(routes); routes.ShouldMap("~/Admin/Main").To <MainController>(x => x.Index()); }
protected void Application_Start() { //string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log4Net.config"); //var fileInfo = new FileInfo(configPath); //XmlConfigurator.ConfigureAndWatch(fileInfo); log4net.Config.XmlConfigurator.Configure(); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new AreaViewEngine()); //ViewEngines.Engines.Add(new WebFormViewEngine()); ModelBinders.Binders.DefaultBinder = new SharpModelBinder(); ModelMetadataProviders.Current = new Store.Core.CustomModelMetadataProvider(); ModelValidatorProviders.Providers.Add(new NHibernateValidatorProvider()); this.InitializeServiceLocator(); AreaRegistration.RegisterAllAreas(); RouteRegistrar.RegisterRoutesTo(RouteTable.Routes); IScheduler _scheduler = null; // start up scheduler // construct a factory ISchedulerFactory factory = new StdSchedulerFactory(); // get a scheduler _scheduler = factory.GetScheduler(); // start the scheduler _scheduler.Start(); }
public void RouteTest_JudgeIndex() { var routes = new RouteCollection(); RouteRegistrar.RegisterAll(routes); routes.ShouldMap("~/Judge/Tournament/1").To <TournamentJudgeController>(x => x.JudgeIndex(1, null)); }
public void RouteTest_AdminTournamentJudges() { var routes = new RouteCollection(); RouteRegistrar.RegisterAll(routes); routes.ShouldMap("~/Admin/Tournament/14/JudgeList").To <TournamentAdminController>(x => x.JudgeList(14)); }
public CalculatorModule(RouteRegistrar routeRegistrar, bool useParamsRegistration) { if (useParamsRegistration) routeRegistrar.RegisterServicesInto(this, typeof(AddService), typeof(MultiplyService)); else routeRegistrar.RegisterServicesInto(this, new[] {typeof(AddService), typeof(MultiplyService)}.AsEnumerable()); }
public void RouteTest_Elmah_NoRoute() { var routes = new RouteCollection(); RouteRegistrar.RegisterAll(routes); routes.ShouldMap("~/elmah.axd").ToIgnoredRoute(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { //services.AddMemoryCache(); //Add Cqrs services services.AddSingleton <Router>(new Router()); services.AddSingleton <ICommandSender>(y => y.GetService <Router>()); services.AddSingleton <IEventPublisher>(y => y.GetService <Router>()); services.AddSingleton <IHandlerRegistrar>(y => y.GetService <Router>()); services.AddSingleton <IEventStore, CqrsEventStore>(); services.AddSingleton <ICache, MemoryCache>(); services.AddScoped <IRepository>(y => new CacheRepository(new Repository(y.GetService <IEventStore>()), y.GetService <IEventStore>(), y.GetService <ICache>())); services.AddScoped <ISession, Session>(); //services.AddTransient<IReadModelFacade, ReadModelFacade>(); //Scan for commandhandlers and eventhandlers services.Scan(scan => scan .FromAssemblies(typeof(CurrentOrderCommandHandlers).GetTypeInfo().Assembly) .AddClasses(classes => classes.Where(x => { var allInterfaces = x.GetInterfaces(); return (allInterfaces.Any(y => y.GetTypeInfo().IsGenericType&& y.GetTypeInfo().GetGenericTypeDefinition() == typeof(IHandler <>)) || allInterfaces.Any(y => y.GetTypeInfo().IsGenericType&& y.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICancellableHandler <>))); })) .AsSelf() .WithTransientLifetime() ); //Register routes var serviceProvider = services.BuildServiceProvider(); var registrar = new RouteRegistrar(new Provider(serviceProvider)); registrar.RegisterInAssemblyOf(typeof(CurrentOrderCommandHandlers)); }
protected void Application_Start() { XmlConfigurator.Configure(); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); ModelBinders.Binders.DefaultBinder = new SharpModelBinder(); ModelBinders.Binders.Add(typeof(string), new TrimModelBinder()); ModelBinders.Binders.Add(typeof(SourceDataTablesParam), new SourceDataTablesModelBinder()); ModelValidatorProviders.Providers.Add(new ClientDataTypeModelValidatorProvider()); this.InitializeServiceLocator(); AreaRegistration.RegisterAllAreas(); RouteRegistrar.RegisterRoutesTo(RouteTable.Routes); AsposeInitialiser.SetLicenses(); this.InitialiseAutoMappings(); // avoid problems transforming NHibernate objects to json JsonConvert.DefaultSettings = () => new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, ContractResolver = new NHibernateContractResolver() }; }
public ApiModule(RouteRegistrar routes) { routes.RegisterServicesInto( this, AllTypes.InAssembly.Where( x => x.Namespace.StartsWith("Restall.Nancy.Demo.ServiceRouting.Api") && x.Name.EndsWith("Service"))); }
public static IServiceProvider GetServiceProvider() { if (Services == null) { lock (_servicesLock) { if (Services == null) { var builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(); var config = builder.Build(); config[BlobEventStore.CONNECTIONSTRING_KEY] = LOCALCONNECTIONSTRING; config[BlobSnapshotStore.CONNECTIONSTRING_KEY] = LOCALCONNECTIONSTRING; IConfigurationRoot configuration = builder.Build(); IServiceCollection services = new ServiceCollection(); //Add Cqrs services // ISnapshotStore snapshotStore, ISnapshotStrategy snapshotStrategy services.AddSingleton <Router>(new Router()); services.AddSingleton <ICommandSender>(y => y.GetService <Router>()); services.AddSingleton <IEventPublisher>(y => y.GetService <Router>()); services.AddSingleton <IHandlerRegistrar>(y => y.GetService <Router>()); services.AddSingleton <IQueryProcessor>(y => y.GetService <Router>()); services.AddSingleton <IConfiguration>(config); services.AddSingleton <IEventStore, BlobEventStore>(); services.AddSingleton <ISnapshotStore, BlobSnapshotStore>(); services.AddSingleton <ISnapshotStrategy, AttributeSnapshotStrategy>(); services.AddSingleton <ICache, MemoryCache>(); services.AddScoped <IBlobEventStorePathProvider>(y => new BlobPathProvider("events", "snapshots")); services.AddScoped <IBlobSnapshotStorePathProvider>(y => new BlobPathProvider("events", "snapshots")); services.AddScoped <IRepository>(y => new SnapshotRepository(y.GetService <ISnapshotStore>(), y.GetService <ISnapshotStrategy>(), new Repository(y.GetService <IEventStore>()), y.GetService <IEventStore>())); services.AddScoped <ISession, Session>(); //Scan for commandhandlers and eventhandlers services.Scan(scan => scan .FromAssemblies(typeof(ForumCommandHandlers).GetTypeInfo().Assembly) .AddClasses(classes => classes.Where(x => { var allInterfaces = x.GetInterfaces(); return (allInterfaces.Any(y => y.GetTypeInfo().IsGenericType&& y.GetTypeInfo().GetGenericTypeDefinition() == typeof(IHandler <>)) || allInterfaces.Any(y => y.GetTypeInfo().IsGenericType&& y.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICancellableHandler <>)) || allInterfaces.Any(y => y.GetTypeInfo().IsGenericType&& y.GetTypeInfo().GetGenericTypeDefinition() == typeof(IQueryHandler <,>)) || allInterfaces.Any(y => y.GetTypeInfo().IsGenericType&& y.GetTypeInfo().GetGenericTypeDefinition() == typeof(ICancellableQueryHandler <,>))); })) .AsSelf() .WithTransientLifetime() ); Services = services.BuildServiceProvider(); RouteRegistrar r = new RouteRegistrar(Services); r.RegisterInAssemblyOf(typeof(ForumCommandHandlers)); } } } return(Services); }
public IServiceProvider CreateServiceProvider(IServiceCollection containerBuilder) { var serviceProvider = containerBuilder.BuildServiceProvider(); var registrar = new RouteRegistrar(new Provider(serviceProvider)); registrar.RegisterInAssemblyOf(typeof(InventoryCommandHandlers)); return(serviceProvider); }
public void ExpectAsyncNamedRouteIsResolvedCorrectlyByService(RouteRegistrar registrar, Guid token) { using (var bootstrapper = new Bootstrapper()) { var browser = new Browser(bootstrapper); browser.Get<NamedRouteResponse>("/named/async/" + token).Uri.Should().Be("/some-named-async-route/" + token); } }
public When_registering_all_handlers_in_assembly() { _testHandleRegistrar = new TestHandleRegistrar(); _locator = new TestServiceLocator(_testHandleRegistrar); var register = new RouteRegistrar(_locator); register.RegisterInAssemblyOf(GetType()); }
public void ExpectAsyncNamedRouteIsResolvedCorrectlyByService(RouteRegistrar registrar, Guid token) { using (var bootstrapper = new Bootstrapper()) { var browser = new Browser(bootstrapper); browser.Get <NamedRouteResponse>("/named/async/" + token).Uri.Should().Be("/some-named-async-route/" + token); } }
public When_registering_all_handlers_in_assembly() { _testHandleRegistrar = new TestHandleRegistrar(); _locator = new TestServiceLocator(_testHandleRegistrar); var register = new RouteRegistrar(_locator); register.Register(GetType()); // Changed From RegisterINAssemblyOf to Register to match apparent changes in source file }
public static IApplicationBuilder UseCQRSLiteBus(this IApplicationBuilder builder, params Type[] typesFromAssemblyContainingMessages) { var provider = new HttpProvider(builder.ApplicationServices.GetService <IServiceProvider>()); var registrar = new RouteRegistrar(provider); registrar.Register(typesFromAssemblyContainingMessages); return(builder); }
public static void RegisterInAssemblyOf(this IKernel Kernel, Type type) { ServiceLocator.SetLocatorProvider(() => new NinjectServiceLocator(Kernel)); var registerer = new RouteRegistrar(new Provider(new NinjectServiceLocator(Kernel))); registerer.RegisterInAssemblyOf( type); }
private void RegisterHandlers(IServiceProvider provider) { var registrar = new RouteRegistrar(provider); //registrar.RegisterInAssemblyOf(typeof(LocationEventHandler)); // register command handlers //registrar.RegisterInAssemblyOf(typeof(AppointmentCommandHandler)); }
public static Browser CreateBrowserWithCancellationToken(RouteRegistrar registrar, CancellationToken cancel) { var bootstrapper = new ConfigurableBootstrapper(with => with .Module(new AsyncCancelModule(registrar)) .NancyEngine<NancyEngineWithAsyncCancellation>()); var browser = new Browser(bootstrapper); ((NancyEngineWithAsyncCancellation) bootstrapper.GetEngine()).CancellationToken = cancel; return browser; }
public When_registering_handlers() { _locator = new TestServiceLocator(); var register = new RouteRegistrar(_locator); if (TestHandleRegistrar.HandlerList.Count == 0) { register.Register(GetType()); } }
public CalculatorModule(RouteRegistrar routeRegistrar, bool useParamsRegistration) { if (useParamsRegistration) { routeRegistrar.RegisterServicesInto(this, typeof(AddService), typeof(MultiplyService)); } else { routeRegistrar.RegisterServicesInto(this, new[] { typeof(AddService), typeof(MultiplyService) }.AsEnumerable()); } }
public void ExpectRoutesForMultipleServicesRegisteredByOverloadedRegistrationMethodAreWiredUpAndResolvedCorrectly( string verb, bool useParamsRegistration, RouteRegistrar registrar, [WithinInclusiveRange(-1000, 1000)] int a, [WithinInclusiveRange(-1000, 1000)] int b) { var browser = new Browser(with => with.Module(new CalculatorModule(registrar, useParamsRegistration))); browser.SendFormRequest<CalculatorResponse>(verb, "/add", new AddRequest(a, b)).Result.Should().Be(a + b, " [add]"); browser.SendFormRequest<CalculatorResponse>(verb, "/multiply", new MultiplyRequest(a, b)).Result.Should().Be(a * b, " [multiply]"); }
public static Browser CreateBrowserWithCancellationToken(RouteRegistrar registrar, CancellationToken cancel) { var bootstrapper = new ConfigurableBootstrapper(with => with .Module(new AsyncCancelModule(registrar)) .NancyEngine <NancyEngineWithAsyncCancellation>()); var browser = new Browser(bootstrapper); ((NancyEngineWithAsyncCancellation)bootstrapper.GetEngine()).CancellationToken = cancel; return(browser); }
public void ExpectCancellableRouteIsWiredUpAndResolvedCorrectly( string verb, RouteRegistrar registrar, Guid token, CancellationTokenSource cancel) { var browser = AsyncCancellationBrowserFactory.CreateBrowserWithCancellationToken(registrar, cancel.Token); var request = new LongRunningFormRequest(AsyncSafetyTimeoutSeconds + 1, token); cancel.CancelAfter(TimeSpan.FromMilliseconds(20)); var response = browser.SendFormRequest<CancelResponse>(verb, "/cancel/long-running", request); response.TokenEcho.Should().Be(token); response.WasCancelled.Should().BeTrue(); }
public void ExpectCancellableRouteIsWiredUpAndResolvedCorrectly( string verb, RouteRegistrar registrar, Guid token, CancellationTokenSource cancel) { var browser = AsyncCancellationBrowserFactory.CreateBrowserWithCancellationToken(registrar, cancel.Token); var request = new LongRunningFormRequest(AsyncSafetyTimeoutSeconds + 1, token); cancel.CancelAfter(TimeSpan.FromMilliseconds(20)); var response = browser.SendFormRequest <CancelResponse>(verb, "/cancel/long-running", request); response.TokenEcho.Should().Be(token); response.WasCancelled.Should().BeTrue(); }
public void ExpectRoutesForMultipleServicesRegisteredByOverloadedRegistrationMethodAreWiredUpAndResolvedCorrectly( string verb, bool useParamsRegistration, RouteRegistrar registrar, [WithinInclusiveRange(-1000, 1000)] int a, [WithinInclusiveRange(-1000, 1000)] int b) { var browser = new Browser(with => with.Module(new CalculatorModule(registrar, useParamsRegistration))); browser.SendUrlRequest <CalculatorResponse>(verb, "/add/" + a + "/" + b).Result.Should().Be(a + b, " [add]"); browser.SendUrlRequest <CalculatorResponse>(verb, "/multiply/" + a + "/" + b).Result.Should().Be(a * b, " [multiply]"); }
public void ExpectRegistrarDispatchContextCanBeOverridden(RouteRegistrar registrar, Guid token) { var module = new StubModule(); var service = CreateStubServiceToReturn(token); var factory = CreateStubServiceFactoryFor(service); registrar .WithDispatchContext(x => x.WithServiceFactory(factory)) .RegisterServiceInto(module, typeof(StubService)); new Browser(with => with.Module(module)).Get <Guid>("/whatever").Should().Be(token); }
public IRouteRegistry <TRequest, TResponse> Build() { var segmentParser = _segmentParser ?? new SegmentParser(); var routeRemover = new RouteRemover <TRequest, TResponse>(segmentParser); var routeRegistrar = new RouteRegistrar <TRequest, TResponse>(segmentParser); return(new RouteRegistryFacade <TRequest, TResponse>( routeRemover, routeRegistrar, _router)); }
public void ExpectRegistrarDispatchContextCanBeOverridden(RouteRegistrar registrar, Guid token) { var module = new StubModule(); var service = CreateStubServiceToReturn(token); var factory = CreateStubServiceFactoryFor(service); registrar .WithDispatchContext(x => x.WithServiceFactory(factory)) .RegisterServiceInto(module, typeof(StubService)); new Browser(with => with.Module(module)).Get<Guid>("/whatever").Should().Be(token); }
public void ExpectMethodCannotBeOverriddenByModifyingDispatchContext(RouteRegistrar registrar, Guid goodToken, Guid badToken) { var module = new StubModule(); var service = CreateStubServiceToReturn(goodToken); service.Stub(x => x.StubNonServiceMethod(Arg<Request>.Is.Anything)).Return(badToken); var factory = CreateStubServiceFactoryFor(service); registrar .WithDispatchContext(x => x .WithServiceFactory(factory) .WithMethod(InfoOf.Method<StubService>(svc => svc.StubNonServiceMethod(null)))) .RegisterServiceInto(module, typeof(StubService)); new Browser(with => with.Module(module)).Get<Guid>("/whatever").Should().Be(goodToken); }
public NamedRouteModule(RouteRegistrar registrar) { registrar.RegisterServiceInto(this, typeof(NamedRouteService)); }
public void ExpectRouteIsWiredUpAndResolvedCorrectly(string verb, RouteRegistrar registrar, Guid token) { var browser = new Browser(with => with.Module(new AsyncEchoModule(registrar))); browser.SendUrlRequest<EchoResponse>(verb, "/echo/" + token).TokenEcho.Should().Be(token); }
public AsyncCancelModule(RouteRegistrar registrar) { registrar.RegisterServiceInto(this, typeof(AsyncCancelService)); }
public AsyncEchoModule(RouteRegistrar registrar) { registrar.RegisterServiceInto(this, typeof(AsyncEchoService)); }
public void ExpectOverridingRegistrarDispatchContextMultipleTimesInheritsSettingsFromPreviousContext(RouteRegistrar registrar, Guid token) { var module = new StubModule(); var service = new StubService(); var factory = MockRepository.GenerateMock<Func<Type, object>>(); factory.Stub(x => x(Arg<Type>.Is.Anything)).Return(service); registrar .WithDispatchContext(x => x.WithServiceFactory(factory)) .WithDispatchContext(x => x.WithDefaultResponse(token)) .RegisterServiceInto(module, typeof(StubService)); new Browser(with => with.Module(module)).Get<Guid>("/void").Should().Be(token); factory.AssertWasCalled(x => x(Arg<Type>.Is.Equal(typeof(StubService))), x => x.Repeat.Once()); }
public void RegisterServicesInto_EnumerableOverloadCalledWithNullServiceTypes_ExpectArgumentNullExceptionWithCorrectParamName( RouteRegistrar registrar, NancyModule module) { registrar.Invoking(x => x.RegisterServicesInto(module, (IEnumerable<Type>) null)) .ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("serviceTypes"); }
public void ExpectOriginalDispatchContextRemainsUnmodifiedWhenOverridden(RouteRegistrar registrar, Guid token) { var module = new StubModule(); var factory = MockRepository.GenerateMock<Func<Type, object>>(); registrar .WithDispatchContext(x => x.WithServiceFactory(factory)) .RegisterServiceInto(module, typeof(StubService)); var anotherModule = new StubModule(); registrar.RegisterServiceInto(anotherModule, typeof(StubService)); new Browser(with => with.Module(anotherModule)).Get<object>("/whatever"); factory.AssertWasNotCalled(x => x(Arg<Type>.Is.Anything)); }
public void ExpectRouteIsWiredUpAndResolvedCorrectly(string verb, RouteRegistrar registrar, EchoFormRequest request) { var browser = new Browser(with => with.Module(new EchoModule(registrar))); browser.SendFormRequest<EchoResponse>(verb, "/echo", request).TokenEcho.Should().Be(request.Token); }
public void WithDispatchContext_CalledWithNullContext_ExpectArgumentNullExceptionWithCorrectParamName(RouteRegistrar registrar) { registrar.Invoking(x => x.WithDispatchContext(null)) .ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("context"); }
public void WithDispatchContext_Called_ExpectReturnedRegistrarIsNotTheSameInstanceAsCalledOn(RouteRegistrar registrar) { registrar.WithDispatchContext(x => x).Should().NotBeSameAs(registrar); }
public void RegisterServiceInto_CalledWithNullServiceType_ExpectArgumentNullExceptionWithCorrectParamName( RouteRegistrar registrar, NancyModule module) { registrar.Invoking(x => x.RegisterServiceInto(module, null)) .ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("serviceType"); }
public void RegisterServicesInto_ArrayOverloadCalledWithNullModule_ExpectArgumentNullExceptionWithCorrectParamName(RouteRegistrar registrar) { registrar.Invoking(x => x.RegisterServicesInto(null, typeof(object), typeof(string))) .ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("module"); }