Example #1
0
        /// <summary>
        /// The enable logging.
        /// </summary>
        /// <param name="config">
        /// The config.
        /// </param>
        /// <param name="isEnabled">
        /// The is enabled.
        /// </param>
        /// <returns>
        /// The <see cref="IBootstrapperConfig"/>.
        /// </returns>
        public static IBootstrapperConfig EnableLogging(this IBootstrapperConfig config, bool isEnabled = true)
        {
            ((BootstrapperConfig)config).IsLoggingEnabled = isEnabled;

            var logger = config.Container.ResolveSafe <ILogger>(new NullLogger());

            // add the default logger to container
            if (logger == null)
            {
                logger = new Infrastructure.Logging.Logger(config.Container.Resolve <IDependencyResolver>());
                logger.Debug(() => "Register ILogger on the container");
                config.Container.RegisterInstance(logger);
            }

            // replace the default tracewriter
            logger.Debug(() => "Check if logger is ITraceWriter");
            if (logger is ITraceWriter)
            {
                logger.Debug(() => "Logger is ITraceWriter so replace the service on Configuration");
                ////GlobalConfiguration.Configuration.Services.Replace(typeof(ITraceWriter), logger);
                config.Configuration.Services.Replace(typeof(ITraceWriter), logger);
            }

            return(config);
        }
Example #2
0
 public CoreAuthenticationService(
     IBootstrapperConfig config,
     IDocumentSession session,
     IHttpContextAccessor httpContextAccessor)
 {
     _config              = config;
     _session             = session;
     _httpContextAccessor = httpContextAccessor;
 }
Example #3
0
        /// <summary>
        /// The enable global exception handler.
        /// </summary>
        /// <param name="config">
        /// The config.
        /// </param>
        /// <returns>
        /// The <see cref="IBootstrapperConfig"/>.
        /// </returns>
        public static IBootstrapperConfig EnableGlobalExceptionHandler(this IBootstrapperConfig config)
        {
            var handler = config.Container.ResolveSafe <IExceptionHandler>(config.Logger()) ?? new ExceptionHandler();
            var globalExceptionHandler = new GlobalExceptionHandler(handler, config.Logger());

            ////GlobalConfiguration.Configuration.Services.Replace(typeof(System.Web.Http.ExceptionHandling.IExceptionHandler), globalExceptionHandler);
            config.Configuration.Services.Replace(typeof(System.Web.Http.ExceptionHandling.IExceptionHandler), globalExceptionHandler);
            config.Container.RegisterInstance <System.Web.Http.ExceptionHandling.IExceptionHandler>(globalExceptionHandler);
            return(config);
        }
Example #4
0
        public BootstrapperRegistry(IBootstrapperConfig config)
        {
            ForSingletonOf <IBootstrapperConfig>().Use(config);

            Scan(scan =>
            {
                // Find handlers and validators in the calling assembly.
                scan.TheCallingAssembly();
                scan.AssemblyContainingType(typeof(IRequestHandler <,>));
                scan.AssemblyContainingType(typeof(IValidator <>));
                scan.AssemblyContainingType(typeof(SignUpUser));

                // Connect handlers.
                scan.ConnectImplementationsToTypesClosing(typeof(IRequestHandler <,>));

                // Connect validators.
                scan.ConnectImplementationsToTypesClosing(typeof(IValidator <>));
            });

            // Connect the feature pipeline behavior.
            For(typeof(IPipelineBehavior <,>))
            .Use(typeof(FeaturePipelineBehavior <,>))
            .Scoped();

            // Configure DI for MediatR
            For <ServiceFactory>().Use(ctx => ctx.GetInstance);
            For <IMediator>()
            .Use <Mediator>()
            .Scoped();

            // Configure DI for Marten
            ForSingletonOf <IDocumentStore>()
            .Use(ctx => CreateMartenStore(config.ConnectionString));

            For <IDocumentSession>()
            .Use(ctx => ctx.GetInstance <IDocumentStore>().OpenSession())
            .Scoped();

            For <IFileClient>()
            .Use <FileClient>()
            .Scoped();
            // Configure DI for custom interfaces
            For <ICoreAuthenticationService>()
            .Use <CoreAuthenticationService>()
            .Scoped();

            For <IEmailService>()
            .Use <EmailService>()
            .Scoped();

            //For<I>()
            //    .Use<GeoLocationService>()
            //    .Scoped();
        }
Example #5
0
        /// <summary>
        /// The enable transaction.
        /// </summary>
        /// <param name="config">
        /// The config.
        /// </param>
        /// <param name="isEnabled">
        /// The is enabled.
        /// </param>
        /// <returns>
        /// The <see cref="IBootstrapperConfig"/>.
        /// </returns>
        public static IBootstrapperConfig EnableTransaction(this IBootstrapperConfig config, bool isEnabled = true)
        {
            var logger = config.Container.ResolveSafe <ILogger>(new NullLogger());

            ((BootstrapperConfig)config).IsTransactionEnabled = isEnabled;

            if (((BootstrapperConfig)config).IsTransactionEnabled)
            {
                var controllerActionTransactionInvoker = config.Container.Resolve <ControllerActionTransactionInvoker>();
                logger.Debug(() => "ControllerActionTransactionInvoker initiated");
                //config.Configuration.Services.Replace(typeof(IHttpActionInvoker), new ControllerActionTransactionInvoker());
                config.Configuration.Services.Replace(typeof(IHttpActionInvoker), controllerActionTransactionInvoker);
            }

            return(config);
        }
Example #6
0
        /// <summary>
        /// handle the $type field of the json data
        /// </summary>
        /// <param name="config">
        /// The bootstrapper config
        /// </param>
        /// <param name="typeNameHandling">
        /// TypeNameHandling
        /// </param>
        /// <param name="formatterAssemblyStyle">
        /// FormatterAssemblyStyle
        /// </param>
        /// <returns>
        /// The <see cref="IBootstrapperConfig"/>.
        /// </returns>
        public static IBootstrapperConfig EnableJsonTypeNameHandling(
            this IBootstrapperConfig config,
            TypeNameHandling typeNameHandling             = TypeNameHandling.All,
            FormatterAssemblyStyle formatterAssemblyStyle = FormatterAssemblyStyle.Simple)
        {
            /*
             * GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = typeNameHandling;
             * GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameAssemblyFormat = formatterAssemblyStyle;
             *
             * GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Error = HandleJsonSerializationErrors;*/
            config.Configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling       = typeNameHandling;
            config.Configuration.Formatters.JsonFormatter.SerializerSettings.TypeNameAssemblyFormat = formatterAssemblyStyle;

            config.Configuration.Formatters.JsonFormatter.SerializerSettings.Error = HandleJsonSerializationErrors;

            return(config);
        }
Example #7
0
 public FileClient(IBootstrapperConfig config)
 {
     BaseUrl  = config.BaseUrl;
     BasePath = config.BasePath;
 }
Example #8
0
 public Startup(IConfiguration configuration)
 {
     Configuration      = configuration;
     BootstrapperConfig = new BootstrapperConfig(Configuration);
 }
Example #9
0
 public GeoLocationService(IBootstrapperConfig config, IGeocoder geocoder)
 {
     _config = config;
 }
Example #10
0
 /// <summary>
 /// The disable web api default exception handler.
 /// </summary>
 /// <param name="config">
 /// The config.
 /// </param>
 /// <returns>
 /// The <see cref="IBootstrapperConfig"/>.
 /// </returns>
 public static IBootstrapperConfig DisableWebApiDefaultExceptionHandler(this IBootstrapperConfig config)
 {
     config.Configuration.Services.Replace(typeof(System.Web.Http.ExceptionHandling.IExceptionHandler), new PassthroughException());
     return(config);
 }
Example #11
0
 public static IBootstrapperConfig EnableAntiXssEncoding(this IBootstrapperConfig config)
 {
     config.Configuration.Filters.Add(new AntiXssFilter());
     return(config);
 }
Example #12
0
 /// <summary>
 /// The enable user message.
 /// </summary>
 /// <param name="config">
 /// The config.
 /// </param>
 /// <param name="resourceSet">
 /// The resource set.
 /// </param>
 /// <returns>
 /// The <see cref="IBootstrapperConfig"/>.
 /// </returns>
 public static IBootstrapperConfig EnableUserMessage(this IBootstrapperConfig config, string resourceSet)
 {
     ResourceProvider.ResourceSet = resourceSet;
     return(config);
 }
Example #13
0
 public EmailService(IBootstrapperConfig config)
 {
     _config = config;
 }