Exemplo n.º 1
0
        public static T GetOrAdd <T>(
            [NotNull] this IConventionHostBuilder builder,
            string key,
            [NotNull] Func <T> factory
            )
            where T : class
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            if (!(builder.ServiceProperties[key] is T value))
            {
                value = factory();
                builder.Set(value);
            }

            return(value);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Uses marten.
 /// </summary>
 /// <param name="container">The container.</param>
 /// <param name="options">The options.</param>
 /// <returns>IConventionHostBuilder.</returns>
 public static IConventionHostBuilder UseMarten(
     this IConventionHostBuilder container,
     MartenOptions?options = null
     )
 {
     container.Set(options ?? new MartenOptions());
     container.Scanner.PrependConvention <MartenCommandConvention>();
     container.Scanner.PrependConvention <MartenConvention>();
     return(container);
 }
        /// <summary>
        /// Uses the default application metrics.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <returns>IConventionHostBuilder.</returns>
        public static IConventionHostBuilder UseMetricsWithDefaults([NotNull] this IConventionHostBuilder container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            container.Set(new RocketMetricsOptions()
            {
                UseDefaults = true
            });
            container.Scanner.PrependConvention <HostingMetricsConvention>();
            return(container);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Uses AutoMapper.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="options">The options object</param>
        /// <returns>IConventionHostBuilder.</returns>
        public static IConventionHostBuilder UseAutoMapper(
            [NotNull] this IConventionHostBuilder container,
            AutoMapperOptions?options = null
            )
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            container.Set(options ?? new AutoMapperOptions());
            container.Scanner.PrependConvention <AutoMapperConvention>();
            return(container);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds MediatR.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="serviceConfig">The MediatR service configuration.</param>
        /// <returns>IConventionHostBuilder.</returns>
        public static IConventionHostBuilder UseMediatR(
            this IConventionHostBuilder builder,
            MediatRServiceConfiguration serviceConfig
            )
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (serviceConfig is null)
            {
                throw new ArgumentNullException(nameof(serviceConfig));
            }

            builder.Set(serviceConfig);
            builder.Scanner.PrependConvention <MediatRConvention>();
            return(builder);
        }