Beispiel #1
0
        public MongoEventStore(string connectionString, ITypeCatalog typeCatalog)
        {
            var connectionStringBuilder = new MongoConnectionStringBuilder(connectionString);

            databaseName  = connectionStringBuilder.Database;
            configuration = BuildMongoConfiguration(typeCatalog, connectionString);
        }
 /// <summary>
 /// Creates a new instance of the <see cref="DefaultDiagnostics"/> class.
 /// </summary>
 /// <param name="diagnosticProviders"></param>
 /// <param name="rootPathProvider"></param>
 /// <param name="requestTracing"></param>
 /// <param name="configuration"></param>
 /// <param name="modelBinderLocator"></param>
 /// <param name="responseProcessors"></param>
 /// <param name="routeSegmentConstraints"></param>
 /// <param name="cultureService"></param>
 /// <param name="requestTraceFactory"></param>
 /// <param name="routeMetadataProviders"></param>
 /// <param name="textResource"></param>
 /// <param name="environment"></param>
 /// <param name="typeCatalog"></param>
 /// <param name="assemblyCatalog"></param>
 /// <param name="acceptHeaderCoercionConventions"></param>
 public DefaultDiagnostics(
     IEnumerable <IDiagnosticsProvider> diagnosticProviders,
     IRootPathProvider rootPathProvider,
     IRequestTracing requestTracing,
     NancyInternalConfiguration configuration,
     IModelBinderLocator modelBinderLocator,
     IEnumerable <IResponseProcessor> responseProcessors,
     IEnumerable <IRouteSegmentConstraint> routeSegmentConstraints,
     ICultureService cultureService,
     IRequestTraceFactory requestTraceFactory,
     IEnumerable <IRouteMetadataProvider> routeMetadataProviders,
     ITextResource textResource,
     INancyEnvironment environment,
     ITypeCatalog typeCatalog,
     IAssemblyCatalog assemblyCatalog,
     AcceptHeaderCoercionConventions acceptHeaderCoercionConventions)
 {
     this.diagnosticProviders             = diagnosticProviders;
     this.rootPathProvider                = rootPathProvider;
     this.requestTracing                  = requestTracing;
     this.configuration                   = configuration;
     this.modelBinderLocator              = modelBinderLocator;
     this.responseProcessors              = responseProcessors;
     this.routeSegmentConstraints         = routeSegmentConstraints;
     this.cultureService                  = cultureService;
     this.requestTraceFactory             = requestTraceFactory;
     this.routeMetadataProviders          = routeMetadataProviders;
     this.textResource                    = textResource;
     this.environment                     = environment;
     this.typeCatalog                     = typeCatalog;
     this.assemblyCatalog                 = assemblyCatalog;
     this.acceptHeaderCoercionConventions = acceptHeaderCoercionConventions;
 }
Beispiel #3
0
 public ComponentRegistrations(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     RegisterAll <IBootstrapperExtender>();
     RegisterAll <IVersionModuleExtender>();
     RegisterWithDefault <IComponentManager>(typeof(ComponentManager));
     RegisterWithDefault <INancyLogger>(typeof(NoopLogger));
 }
Beispiel #4
0
        internal static Type GetBootstrapperType(ITypeCatalog typeCatalog)
        {
            var customBootstrappers = GetAvailableBootstrapperTypes(typeCatalog);

            if (!customBootstrappers.Any())
            {
                return(typeof(DefaultNancyBootstrapper));
            }

            if (customBootstrappers.Count == 1)
            {
                return(customBootstrappers.Single());
            }

            Type bootstrapper;

            if (TryFindMostDerivedType(customBootstrappers, out bootstrapper))
            {
                return(bootstrapper);
            }

            var errorMessage = GetMultipleBootstrappersMessage(customBootstrappers);

            throw new BootstrapperException(errorMessage);
        }
Beispiel #5
0
 public FakeDiagnostics(
     IRootPathProvider rootPathProvider,
     IRequestTracing requestTracing,
     NancyInternalConfiguration configuration,
     IModelBinderLocator modelBinderLocator,
     IEnumerable <IResponseProcessor> responseProcessors,
     IEnumerable <IRouteSegmentConstraint> routeSegmentConstraints,
     ICultureService cultureService,
     IRequestTraceFactory requestTraceFactory,
     IEnumerable <IRouteMetadataProvider> routeMetadataProviders,
     ITextResource textResource,
     INancyEnvironment environment,
     ITypeCatalog typeCatalog)
 {
     this.diagnosticProviders     = (new IDiagnosticsProvider[] { new FakeDiagnosticsProvider() }).ToArray();
     this.rootPathProvider        = rootPathProvider;
     this.requestTracing          = requestTracing;
     this.configuration           = configuration;
     this.modelBinderLocator      = modelBinderLocator;
     this.responseProcessors      = responseProcessors;
     this.routeSegmentConstraints = routeSegmentConstraints;
     this.cultureService          = cultureService;
     this.requestTraceFactory     = requestTraceFactory;
     this.routeMetadataProviders  = routeMetadataProviders;
     this.textResource            = textResource;
     this.environment             = environment;
     this.typeCatalog             = typeCatalog;
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HydraRegistrations"/> class.
 /// </summary>
 public HydraRegistrations(ITypeCatalog catalog)
     : base(catalog)
 {
     this.RegisterWithDefault <IApiDocumentationFactory>(typeof(ApiDocumentationFactory), Lifetime.PerRequest);
     this.RegisterWithDefault <IRdfTypeProviderPolicy>(typeof(AttributeRdfTypeProviderPolicy));
     this.RegisterWithDefault <ISupportedPropertySelectionPolicy>(typeof(DefaultPropertiesSelectionPolicy));
     this.RegisterWithDefault <ISupportedPropertyFactory>(typeof(DefaultSupportedPropertyFactory), Lifetime.PerRequest);
     this.RegisterWithDefault <ISupportedClassFactory>(typeof(DefaultSupportedClassFactory), Lifetime.PerRequest);
     this.RegisterWithDefault <ISupportedPropertyMetaProvider>(typeof(DefaultSupportedPropertyMetaProvider));
     this.RegisterWithDefault <ISupportedClassMetaProvider>(typeof(DefaultSupportedClassMetaProvider));
     this.RegisterWithDefault <IPropertyPredicateIdPolicy>(typeof(DefaultPropertyIdPolicy));
     this.RegisterWithDefault <IPropertyRangeRetrievalPolicy>(typeof(DefaultPropertyRangeRetrievalPolicy), Lifetime.PerRequest);
     this.RegisterWithDefault <ISupportedOperationFactory>(typeof(DefaultSupportedOperationFactory), Lifetime.PerRequest);
     this.RegisterWithDefault <IContextProvider>(typeof(NullContextProvider));
     this.RegisterWithDefault <IUriTemplateExpander>(typeof(DefaultUriTemplateExpander));
     this.RegisterWithDefault <IUriTemplateMatcher>(typeof(DefaultUriTemplateMatcher));
     this.RegisterWithDefault <IIriTemplateFactory>(typeof(IriTemplateFactory), Lifetime.PerRequest);
     this.RegisterWithUserThenDefault <IDocumentedTypeSelector>(new[]
     {
         typeof(HydraBuiltInTypesSelector)
     });
     this.Register <IPropertyRangeMappingPolicy>(new[]
     {
         typeof(XsdDatatypesMappingPolicy),
         typeof(XsdDatatypesNullablesMappingPolicy),
         typeof(SupportedClassRangeMappingPolicy),
     });
 }
Beispiel #7
0
 /// <summary>
 /// Creates a new instance of the <see cref="DefaultDiagnostics"/> class.
 /// </summary>
 /// <param name="diagnosticProviders"></param>
 /// <param name="rootPathProvider"></param>
 /// <param name="requestTracing"></param>
 /// <param name="configuration"></param>
 /// <param name="modelBinderLocator"></param>
 /// <param name="responseProcessors"></param>
 /// <param name="routeSegmentConstraints"></param>
 /// <param name="cultureService"></param>
 /// <param name="requestTraceFactory"></param>
 /// <param name="routeMetadataProviders"></param>
 /// <param name="textResource"></param>
 /// <param name="environment"></param>
 /// <param name="typeCatalog"></param>
 public DefaultDiagnostics(
     IEnumerable<IDiagnosticsProvider> diagnosticProviders,
     IRootPathProvider rootPathProvider,
     IRequestTracing requestTracing,
     NancyInternalConfiguration configuration,
     IModelBinderLocator modelBinderLocator,
     IEnumerable<IResponseProcessor> responseProcessors,
     IEnumerable<IRouteSegmentConstraint> routeSegmentConstraints,
     ICultureService cultureService,
     IRequestTraceFactory requestTraceFactory,
     IEnumerable<IRouteMetadataProvider> routeMetadataProviders,
     ITextResource textResource,
     INancyEnvironment environment,
     ITypeCatalog typeCatalog)
 {
     this.diagnosticProviders = diagnosticProviders;
     this.rootPathProvider = rootPathProvider;
     this.requestTracing = requestTracing;
     this.configuration = configuration;
     this.modelBinderLocator = modelBinderLocator;
     this.responseProcessors = responseProcessors;
     this.routeSegmentConstraints = routeSegmentConstraints;
     this.cultureService = cultureService;
     this.requestTraceFactory = requestTraceFactory;
     this.routeMetadataProviders = routeMetadataProviders;
     this.textResource = textResource;
     this.environment = environment;
     this.typeCatalog = typeCatalog;
 }
        private static TinyIoCContainer ConfigureContainer(IEnumerable<IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, INancyEnvironment diagnosticsEnvironment, ITypeCatalog typeCatalog, IAssemblyCatalog assemblyCatalog)
        {
            var diagContainer = new TinyIoCContainer();

            diagContainer.Register<IInteractiveDiagnostics, InteractiveDiagnostics>();
            diagContainer.Register<IRequestTracing>(requestTracing);
            diagContainer.Register<IRootPathProvider>(rootPathProvider);
            diagContainer.Register<NancyInternalConfiguration>(configuration);
            diagContainer.Register<IModelBinderLocator, DefaultModelBinderLocator>();
            diagContainer.Register<IBinder, DefaultBinder>();
            diagContainer.Register<IFieldNameConverter, DefaultFieldNameConverter>();
            diagContainer.Register<BindingDefaults, BindingDefaults>();
            diagContainer.Register<INancyEnvironment>(diagnosticsEnvironment);
            diagContainer.Register<ISerializer>(new DefaultJsonSerializer(diagnosticsEnvironment));
            diagContainer.Register<ITypeCatalog>(typeCatalog);
            diagContainer.Register<IAssemblyCatalog>(assemblyCatalog);


            foreach (var diagnosticsProvider in providers)
            {
                var key = string.Concat(
                    diagnosticsProvider.GetType().FullName,
                    "_",
                    diagnosticsProvider.DiagnosticObject.GetType().FullName);

                diagContainer.Register<IDiagnosticsProvider>(diagnosticsProvider, key);
            }

            foreach (var moduleType in typeCatalog.GetTypesAssignableTo<DiagnosticModule>())
            {
                diagContainer.Register(typeof(INancyModule), moduleType, moduleType.FullName).AsMultiInstance();
            }

            return diagContainer;
        }
Beispiel #9
0
        public static IDictionary <Type, LocalCommandBus.CommandHandlerInvoker> CreateADictionaryOfCommandInvokers(
            ITypeCatalog typeCatalog, IServiceLocator serviceLocator)
        {
            var types = GetAllCommandHandlerTypes(typeCatalog);

            return(CreateCommandInvokersForTheseTypes(types, serviceLocator));
        }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Installer"/> class.
 /// </summary>
 public Installer(ITypeCatalog typeCatalog)
     : base(typeCatalog)
 {
     this.RegisterWithDefault <INamespaceManager>(typeof(DictionaryNamespaceManager));
     this.RegisterWithDefault <IContextPathMapper>(typeof(DefaultContextPathMapper));
     this.Register <IEntitySerializer>(typeof(EntitySerializer));
 }
Beispiel #11
0
        public Installer(ITypeCatalog typeCatalog)
            : base(typeCatalog)
        {
            IWikibusConfiguration configuration = new AppSettingsConfiguration();

            this.Register(configuration);
        }
Beispiel #12
0
        public MvcEngine RegisterControllerCatalog(string a_directory, string a_suffix = "", Type a_baseType = null)
        {
            var assembly = Assembly.GetCallingAssembly();

            _controllerCatalog = new DirectoryCatalog(_container, assembly, a_directory, a_suffix, a_baseType ?? typeof(ControllerBase));

            return(this);
        }
 public SwaggerRegistrations(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     RegisterWithDefault<ISwaggerMetadataProvider>(typeof(DefaultSwaggerMetadataProvider));
     RegisterWithDefault<ISwaggerModelCatalog>(typeof(DefaultSwaggerModelCatalog));
     RegisterWithDefault<ISwaggerTagCatalog>(typeof(DefaultSwaggerTagCatalog));
     RegisterAll<ISwaggerModelDataProvider>();
     RegisterAll<ISwaggerTagProvider>();
 }
Beispiel #14
0
        public CollectionTypeRegistration GetRegistration(ITypeCatalog typeCatalog)
        {
            Check.NotNull(typeCatalog, nameof(typeCatalog));

            return(GetRegistration(this.implementationTypes, this.lifetime)
                   ?? ScanForCustomImplementations(typeCatalog, this.lifetime)
                   ?? GetDefaultRegistration(this.defaultImplementationTypes, this.lifetime));
        }
Beispiel #15
0
        public TypeRegistration GetRegistration(ITypeCatalog typeCatalog)
        {
            Check.NotNull(typeCatalog, nameof(typeCatalog));

            return(this.registration
                   ?? ScanForCustomRegistration(typeCatalog, this.lifetime)
                   ?? GetDefaultRegistration(this.lifetime));
        }
Beispiel #16
0
        /// <summary>
        /// Register the given type catalog (<paramref name="a_catalog"/>) to use as this engine's view catalog.
        /// </summary>
        /// <param name="a_catalog"></param>
        /// <returns></returns>
        public MvcEngine RegisterViewCatalog(ITypeCatalog a_catalog)
        {
            var viewHandler = GetViewHandler();

            viewHandler.RegisterViewCatalog(a_catalog);

            return(this);
        }
 public SwaggerRegistrations(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     RegisterWithDefault <ISwaggerMetadataProvider>(typeof(DefaultSwaggerMetadataProvider));
     RegisterWithDefault <ISwaggerModelCatalog>(typeof(DefaultSwaggerModelCatalog));
     RegisterWithDefault <ISwaggerTagCatalog>(typeof(DefaultSwaggerTagCatalog));
     RegisterAll <ISwaggerModelDataProvider>();
     RegisterAll <ISwaggerTagProvider>();
 }
        public MongoEventStore(string connectionString, ITypeCatalog typeCatalog)
        {
            _eventHashRef = new Dictionary<string, string>();
            typeCatalog.GetDerivedTypes(typeof(DomainEvent)).ToList().
                ForEach(x => BsonClassMap.RegisterClassMap(new DomainEventMapper(x, _eventHashRef)));

            var connection = new MongoUrlBuilder(connectionString);
            _collection = MongoServer.Create(connection.ToMongoUrl()).GetDatabase(connection.DatabaseName).GetCollection<DomainEvent>("events");
        }
        public MongoEventStore(string connectionString, ITypeCatalog typeCatalog)
        {
            var connectionStringBuilder = new MongoConnectionStringBuilder(connectionString);
            var configuration = BuildMongoConfiguration(typeCatalog, connectionString);
            var mongo = new Mongo(configuration);
            mongo.Connect();

            database = mongo.GetDatabase(connectionStringBuilder.Database);
        }
Beispiel #20
0
        public MongoSnapshotStore(string connectionString, ITypeCatalog snapshotTypeCatalog)
        {
            var configuration = BuildMongoConfiguration(snapshotTypeCatalog, connectionString);
            var mongo         = new Mongo(configuration);

            mongo.Connect();

            database = mongo.GetDatabase("snapshotstore");
        }
Beispiel #21
0
        public FileEventStore(string baseDirectory, ITypeCatalog typeCatalog)
        {
            this.baseDirectory = baseDirectory;
            if (!Directory.Exists(baseDirectory))
                Directory.CreateDirectory(baseDirectory);

            var domainEventDerivedTypes = typeCatalog.GetDerivedTypes(typeof(DomainEvent));
            serializer = new DataContractSerializer(typeof(DomainEvent), domainEventDerivedTypes);
        }
Beispiel #22
0
        public MongoEventStore(string connectionString, ITypeCatalog typeCatalog)
        {
            var connectionStringBuilder = new MongoConnectionStringBuilder(connectionString);
            var configuration           = BuildMongoConfiguration(typeCatalog, connectionString);
            var mongo = new Mongo(configuration);

            mongo.Connect();

            database = mongo.GetDatabase(connectionStringBuilder.Database);
        }
 private static bool GetDebugMode(ITypeCatalog typeCatalog)
 {
     try
     {
         return Debugger.IsAttached;
     }
     catch
     {
         return false;
     }
 }
 private static bool GetDebugMode(ITypeCatalog typeCatalog)
 {
     try
     {
         return(Debugger.IsAttached);
     }
     catch
     {
         return(false);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentsInstaller"/> class.
        /// </summary>
        /// <param name="databaseSettings">Database configuration provider</param>
        /// <param name="catalog">Nancy type catalog</param>
        public ComponentsInstaller(ITypeCatalog catalog, IConfiguration c)
            : base(catalog)
        {
            IWikibusConfiguration configuration = new AppSettingsConfiguration(c);

            this.Register(configuration);
            this.Register <IFrameProvider>(new WikibusModelFrames());
            this.Register <DefaultRouteResolver>();
            this.Register <IRdfConverter>(typeof(RdfConverter));
            this.RegisterAll <ISupportedOperations>(Lifetime.PerRequest);
        }
Beispiel #26
0
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !DNX
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new LibraryManagerAssemblyCatalog();
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
Beispiel #27
0
        public HydraRegistrations(ITypeCatalog catalog)
            : base(catalog)
        {
            Register <IHydraDocumentationSettings>(new HydraDocumentationSettings());

            // todo: move to Lernaean.Hydra.Nancy when bug NancyFx/Nancy#2384 is fixed
            RegisterAll <ISupportedOperations>(Lifetime.PerRequest);
            Register <IBaseUriProvider>(new BaseProvider());

            Register <IUriTemplateExpander>(typeof(TunnelVisionLabsUriTemplateExpander));
            Register <IUriTemplateMatcher>(typeof(TunnelVisionLabsUriTemplateMatcher));
        }
Beispiel #28
0
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !CORE
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new DependencyContextAssemblyCatalog();
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !DNX
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new LibraryManagerAssemblyCatalog();
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if !CORE
            assemblyCatalog = new AppDomainAssemblyCatalog();
#else
            assemblyCatalog = new DependencyContextAssemblyCatalog();
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
Beispiel #31
0
        public FileEventStore(string baseDirectory, ITypeCatalog typeCatalog)
        {
            this.baseDirectory = baseDirectory;
            if (!Directory.Exists(baseDirectory))
            {
                Directory.CreateDirectory(baseDirectory);
            }

            var domainEventDerivedTypes = typeCatalog.GetDerivedTypes(typeof(DomainEvent));

            serializer = new DataContractSerializer(typeof(DomainEvent), domainEventDerivedTypes);
        }
Beispiel #32
0
        public NancyInternalConfigurationFixture()
        {
            IAssemblyCatalog assemblyCatalog;

#if CORE
            assemblyCatalog = new DependencyContextAssemblyCatalog();
#else
            assemblyCatalog = null; // new AppDomainAssemblyCatalog(); TODO: This needs fixed!
#endif

            this.typeCatalog = new DefaultTypeCatalog(assemblyCatalog);
        }
Beispiel #33
0
        private static CollectionTypeRegistration ScanForCustomImplementations(ITypeCatalog typeCatalog, Lifetime lifetime)
        {
            var customImplementationTypes = typeCatalog
                                            .GetTypesAssignableTo <TService>(ScanningStrategies.ExcludeNancy)
                                            .ToArray();

            if (customImplementationTypes.Length > 0)
            {
                return(new CollectionTypeRegistration(typeof(TService), customImplementationTypes, lifetime));
            }

            return(null);
        }
Beispiel #34
0
        private static TypeRegistration ScanForCustomRegistration(ITypeCatalog typeCatalog, Lifetime lifetime)
        {
            // TODO: Throw on multiple results?
            var customImplementationType = typeCatalog
                                           .GetTypesAssignableTo <TService>(ScanningStrategies.ExcludeNancy)
                                           .FirstOrDefault();

            if (customImplementationType != null)
            {
                return(new TypeRegistration(typeof(TService), customImplementationType, lifetime));
            }

            return(null);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentsInstaller"/> class.
        /// </summary>
        /// <param name="databaseSettings">Database configuration provider</param>
        /// <param name="catalog">Nancy type catalog</param>
        public ComponentsInstaller(ISourcesDatabaseSettings databaseSettings, ITypeCatalog catalog)
            : base(catalog)
        {
            IWikibusConfiguration configuration = new AppSettingsConfiguration();

            this.Register(configuration);
            this.Register(new Lazy <ISparqlQueryProcessor>(() =>
            {
                var endpointUri = databaseSettings.SourcesSparqlEndpoint;
                return(new RemoteQueryProcessor(new SparqlRemoteEndpoint(endpointUri)));
            }));
            this.Register <IFrameProvider>(new WikibusModelFrames());
            this.Register <DefaultRouteResolver>();
        }
        // Register each application setting so a factory method is invoked when injected
        // into a dependent component.  The factory method delegates to Microsoft's base
        // implementation.
        public override void ScanPlugins(ITypeCatalog catalog)
        {
            catalog.AsDescriptor(
                t => t.IsConcreteTypeDerivedFrom <IAppSettings>(),
                st => ServiceDescriptor.Singleton(st, sp => {
                Type optionsType = typeof(IOptions <>).MakeGenericType(st);

                dynamic options    = sp.GetRequiredService(optionsType);
                object appSettings = options.Value;

                SettingsExtensions.ValidateSettings(Context.Logger, appSettings);
                return(appSettings);
            }));
        }
        private static MongoConfiguration BuildMongoConfiguration(ITypeCatalog domainEventTypeCatalog, string connectionString)
        {
            var configurationBuilder = new MongoConfigurationBuilder();
            configurationBuilder.ConnectionString(connectionString);
            configurationBuilder.Mapping(mapping =>
                                             {
                                                 mapping.DefaultProfile(profile => profile.SubClassesAre(t => t.IsSubclassOf(typeof(DomainEvent))));
                                                 domainEventTypeCatalog
                                                     .GetDerivedTypes(typeof(DomainEvent))
                                                     .ToList()
                                                     .ForEach(type => MapEventType(type, mapping));
                                             });

            return configurationBuilder.BuildConfiguration();
        }
 public AzureStorageRegistrations(ITypeCatalog typeCatalog, IConfiguration configuration)
     : base(typeCatalog)
 {
     if (configuration["azure:storage:connectionString"] == null)
     {
         LogTo.Information("Azure Storage no set up. Using local filesystem");
         this.Register <IFileStorage>(new LocalFileStorage());
         this.Register <IStorageQueue>(new NullStorageQueue());
     }
     else
     {
         this.Register <IFileStorage>(typeof(BlobFileStorage));
         this.Register <IStorageQueue>(typeof(StorageQueue));
     }
 }
Beispiel #39
0
        /// <summary>
        /// Register the given view catalog for this handler.
        /// </summary>
        /// <param name="a_viewCatalog">View catalog.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_viewCatalog"/> is null.</exception>
        public ViewHandler RegisterViewCatalog(ITypeCatalog a_viewCatalog)
        {
            #region Argument Validation

            if (a_viewCatalog == null)
            {
                throw new ArgumentNullException(nameof(a_viewCatalog));
            }

            #endregion

            _viewCatalog = a_viewCatalog;

            return(this);
        }
Beispiel #40
0
        /// <summary>
        /// Register the given type catalog (<paramref name="a_catalog"/>) to use as this engine's controller catalog.
        /// </summary>
        /// <param name="a_catalog"></param>
        /// <returns>This engine (fluent interface).</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="a_catalog"/> is null.</exception>
        public MvcEngine RegisterControllerCatalog(ITypeCatalog a_catalog)
        {
            #region Argument Validation

            if (a_catalog == null)
            {
                throw new ArgumentNullException(nameof(a_catalog));
            }

            #endregion

            _controllerCatalog = a_catalog;

            return(this);
        }
        private static bool GetDebugMode(ITypeCatalog typeCatalog)
        {
            try
            {
                var assembliesInDebug = typeCatalog
                    .GetTypesAssignableTo<INancyModule>(TypeResolveStrategies.ExcludeNancy)
                    .Select(x => x.Assembly.GetCustomAttributes(typeof(DebuggableAttribute), true))
                    .Where(x => x.Length != 0);

                return assembliesInDebug.Any(d => ((DebuggableAttribute)d[0]).IsJITTrackingEnabled);
            }
            catch
            {
                return false;
            }
        }
Beispiel #42
0
        public InfoModule(IRootPathProvider rootPathProvider, NancyInternalConfiguration configuration, INancyEnvironment environment, ITypeCatalog typeCatalog)
            : base("/info")
        {
            this.typeCatalog = typeCatalog;

            Get["/"] = async (_, __) =>
            {
                return View["Info"];
            };

            Get["/data"] = async (_, __) =>
            {
                dynamic data = new ExpandoObject();



                data.Nancy = new ExpandoObject();
                data.Nancy.Version = string.Format("v{0}", this.GetType().Assembly.GetName().Version.ToString());
                data.Nancy.TracesDisabled = !environment.GetValue<TraceConfiguration>().DisplayErrorTraces;
                data.Nancy.CaseSensitivity = StaticConfiguration.CaseSensitive ? "Sensitive" : "Insensitive";
                data.Nancy.RootPath = rootPathProvider.GetRootPath();
                data.Nancy.Hosting = GetHosting();
                data.Nancy.BootstrapperContainer = GetBootstrapperContainer();
                data.Nancy.LocatedBootstrapper = NancyBootstrapperLocator.Bootstrapper.GetType().ToString();
                data.Nancy.LoadedViewEngines = GetViewEngines();

                data.Configuration = new Dictionary<string, object>();
                foreach (var propertyInfo in configuration.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    var value =
                        propertyInfo.GetValue(configuration, null);

                    data.Configuration[propertyInfo.Name] = (!typeof(IEnumerable).IsAssignableFrom(value.GetType())) ?
                        new[] { value.ToString() } :
                        ((IEnumerable<object>)value).Select(x => x.ToString());
                }

                return this.Response.AsJson((object)data);
            };
        }
 /// <summary>
 /// Creates a new instance of the <see cref="DataAnnotationsRegistrations"/> class, that performs
 /// the default registrations of the Data Annotations types.
 /// </summary>
 /// <param name="typeCatalog">An <see cref="ITypeCatalog"/> instance.</param>
 public DataAnnotationsRegistrations(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     this.RegisterAll<IDataAnnotationsValidatorAdapter>();
     this.RegisterWithDefault<IPropertyValidatorFactory>(typeof(DefaultPropertyValidatorFactory));
     this.RegisterWithDefault<IValidatableObjectAdapter>(typeof(DefaultValidatableObjectAdapter));
 }
 /// <summary>
 /// Creates a new instance of the <see cref="MetadataModuleRegistrations"/> class, that performs
 /// the default registrations of the metadata modules types.
 /// </summary>
 /// <param name="typeCatalog">An <see cref="ITypeCatalog"/> instance.</param>
 public MetadataModuleRegistrations(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     this.Register<DefaultMetadataModuleConventions>();
     this.RegisterAll<IMetadataModule>();
     this.RegisterWithDefault<IMetadataModuleResolver>(typeof(DefaultMetadataModuleResolver));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorViewEngineRegistrations"/> class.
 /// </summary>
 /// <param name="typeCatalog">An <see cref="ITypeCatalog"/> instance.</param>
 public RazorViewEngineRegistrations(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     this.RegisterWithDefault<IRazorConfiguration>(typeof(DefaultRazorConfiguration));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultRuntimeEnvironmentInformation"/> class.
 /// </summary>
 /// <param name="typeCatalog">An <see cref="ITypeCatalog"/> instance.</param>
 public DefaultRuntimeEnvironmentInformation(ITypeCatalog typeCatalog)
 {
     this.isDebug = new Lazy<bool>(() => GetDebugMode(typeCatalog));
 }
 /// <summary>
 /// Creates a new instance of the <see cref="FluentValidationRegistrations"/> class, that performs
 /// the default registrations of the Fluent Validation types.
 /// </summary>
 /// <param name="typeCatalog">An <see cref="ITypeCatalog"/> instance.</param>
 public FluentValidationRegistrations(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     this.Register<IFluentAdapterFactory>(typeof(DefaultFluentAdapterFactory));
     this.RegisterAll<IFluentAdapter>();
     this.RegisterAll<IValidator>();
 }
 public DomainEventReplayer(IEventStore eventStore, IEventBus eventBus, ITypeCatalog typeCatalog)
 {
     _eventStore = eventStore;
     _eventBus = eventBus;
     _typeCatalog = typeCatalog;
 }
Beispiel #49
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NancyConventions"/> class.
 /// </summary>
 public NancyConventions(ITypeCatalog typeCatalog)
 {
     this.typeCatalog = typeCatalog;
     this.BuildDefaultConventions();
 }
 public ApplicationRegistrationTask(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     Register<IType1>(typeof(Type));
     Register<IType2>(typeof(Type));
 }
Beispiel #51
0
        /// <summary>
        /// Enables the diagnostics dashboard and will intercept all requests that are passed to
        /// the condigured paths.
        /// </summary>
        public static void Enable(IPipelines pipelines, IEnumerable<IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, IModelBinderLocator modelBinderLocator, IEnumerable<IResponseProcessor> responseProcessors, IEnumerable<IRouteSegmentConstraint> routeSegmentConstraints, ICultureService cultureService, IRequestTraceFactory requestTraceFactory, IEnumerable<IRouteMetadataProvider> routeMetadataProviders, ITextResource textResource, INancyEnvironment environment, ITypeCatalog typeCatalog)
        {
            var diagnosticsConfiguration =
                environment.GetValue<DiagnosticsConfiguration>();

            var diagnosticsEnvironment =
                GetDiagnosticsEnvironment();

            var diagnosticsModuleCatalog = new DiagnosticsModuleCatalog(providers, rootPathProvider, requestTracing, configuration, diagnosticsEnvironment, typeCatalog);

            var diagnosticsRouteCache = new RouteCache(
                diagnosticsModuleCatalog,
                new DefaultNancyContextFactory(cultureService, requestTraceFactory, textResource, environment),
                new DefaultRouteSegmentExtractor(),
                new DefaultRouteDescriptionProvider(),
                cultureService,
                routeMetadataProviders);

            var diagnosticsRouteResolver = new DefaultRouteResolver(
                diagnosticsModuleCatalog,
                new DiagnosticsModuleBuilder(rootPathProvider, modelBinderLocator, diagnosticsEnvironment, environment),
                diagnosticsRouteCache,
                new RouteResolverTrie(new TrieNodeFactory(routeSegmentConstraints)),
                environment);

            var serializer = new DefaultObjectSerializer();

            pipelines.BeforeRequest.AddItemToStartOfPipeline(
                new PipelineItem<Func<NancyContext, Response>>(
                    PipelineKey,
                    ctx =>
                    {
                        if (!ctx.ControlPanelEnabled)
                        {
                            return null;
                        }

                        if (!ctx.Request.Path.StartsWith(diagnosticsConfiguration.Path, StringComparison.OrdinalIgnoreCase))
                        {
                            return null;
                        }

                        if (!diagnosticsConfiguration.Enabled)
                        {
                            return HttpStatusCode.NotFound;
                        }

                        ctx.Items[ItemsKey] = true;

                        var resourcePrefix =
                            string.Concat(diagnosticsConfiguration.Path, "/Resources/");

                        if (ctx.Request.Path.StartsWith(resourcePrefix, StringComparison.OrdinalIgnoreCase))
                        {
                            var resourceNamespace = "Nancy.Diagnostics.Resources";

                            var path = Path.GetDirectoryName(ctx.Request.Url.Path.Replace(resourcePrefix, string.Empty)) ?? string.Empty;
                            if (!string.IsNullOrEmpty(path))
                            {
                                resourceNamespace += string.Format(".{0}", path.Replace(Path.DirectorySeparatorChar, '.'));
                            }

                            return new EmbeddedFileResponse(
                                typeof(DiagnosticsHook).Assembly,
                                resourceNamespace,
                                Path.GetFileName(ctx.Request.Url.Path));
                        }

                        RewriteDiagnosticsUrl(diagnosticsConfiguration, ctx);

                        return ValidateConfiguration(diagnosticsConfiguration)
                                   ? ExecuteDiagnostics(ctx, diagnosticsRouteResolver, diagnosticsConfiguration, serializer, diagnosticsEnvironment)
                                   : new DiagnosticsViewRenderer(ctx, environment)["help"];
                    }));
        }
 public NancyInternalConfigurationFixture()
 {
     this.typeCatalog = new DefaultTypeCatalog(new AppDomainAssemblyCatalog());
 }
Beispiel #53
0
 public MongoEventStore(string connectionString, ITypeCatalog typeCatalog)
 {
     var connectionStringBuilder = new MongoConnectionStringBuilder(connectionString);
     databaseName = connectionStringBuilder.Database;
     configuration = BuildMongoConfiguration(typeCatalog, connectionString);
 }
 public DiagnosticsModuleCatalog(IEnumerable<IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, INancyEnvironment diagnosticsEnvironment, ITypeCatalog typeCatalog, IAssemblyCatalog assemblyCatalog)
 {
     this.container = ConfigureContainer(providers, rootPathProvider, requestTracing, configuration, diagnosticsEnvironment, typeCatalog, assemblyCatalog);
 }
 public static IDictionary<Type, LocalCommandBus.CommandHandlerInvoker> CreateADictionaryOfCommandInvokers(
     ITypeCatalog typeCatalog, IServiceLocator serviceLocator)
 {
     var types = GetAllCommandHandlerTypes(typeCatalog);
     return CreateCommandInvokersForTheseTypes(types, serviceLocator);
 }
 private static IEnumerable<Type> GetAllCommandHandlerTypes(ITypeCatalog typeCatalog)
 {
     return typeCatalog.GetGenericInterfaceImplementations(typeof (IHandleCommands<>));
 }
 /// <summary>
 /// Register the <c>RubyNamingConvention</c> as the default.
 /// </summary>
 /// <param name="typeCatalog">An <see cref="ITypeCatalog"/> instance.</param>
 public DotLiquidRegistrations(ITypeCatalog typeCatalog) : base(typeCatalog)
 {
     this.RegisterWithDefault<INamingConvention>(typeof(RubyNamingConvention));
 }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="Nancy.ViewEngines.SuperSimpleViewEngine.SuperSimpleViewEngineRegistrations"/> class.
 /// </summary>
 /// <param name="typeCatalog">Type catalog.</param>
 public SuperSimpleViewEngineRegistrations (ITypeCatalog typeCatalog)
 {
     this.typeCatalog = typeCatalog;
 }