public static IServiceCollection AddMicroService(this IServiceCollection services,Action<IMicroServiceBuilder> configureBuilder)
        {
            var builder = new MicroServiceBuilder(services);

            configureBuilder(builder);
            return services;
        }
        public static MicroServiceBuilder AddMetadatas(this MicroServiceBuilder builder)
        {
            builder.Settings.EnableMetadatas = true;

            builder.Services.AddSingleton(new MicroServiceMetadatas());

            return(builder);
        }
        public static MicroServiceBuilder AddJson(this MicroServiceBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddSingleton(new JsonOptions());
            builder.Services.AddSingleton <IJsonService, JsonService>();

            return(builder);
        }
        public static IServiceCollection AddMicroService(this IServiceCollection services, Action <MicroServiceBuilder> handler = null, Action <MicroServiceSettings> settingsHandler = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var settings = new MicroServiceSettings();

            settingsHandler?.Invoke(settings);
            services.AddSingleton(settings);

            var builder = new MicroServiceBuilder(services, settings);

            handler?.Invoke(builder);
            return(services);
        }
        public static MicroServiceBuilder AddJson(this MicroServiceBuilder builder, Action <JsonSerializerSettings> handler)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            var jsonOptions = new JsonOptions();

            handler(jsonOptions.SerializerSettings);
            builder.Services.AddSingleton(jsonOptions);
            builder.Services.AddSingleton <IJsonService, JsonService>();

            return(builder);
        }
Beispiel #6
0
        public static MicroServiceBuilder AddSwagger(this MicroServiceBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            builder.Services.Configure(new Action <SwaggerGenOptions>(c =>
            {
                c.SwaggerDoc("v1",
                             new Info
                {
                    Version        = "v1",
                    Title          = "Swashbuckle Sample API",
                    Description    = "A sample API for testing Swashbuckle",
                    TermsOfService = "Some terms ..."
                }
                             );
            }));
            builder.Services.AddTransient <ISwaggerProvider>(sp => new MicroServiceSwaggerGenerator(sp));

            return(builder);
        }