public static IUkiyoBuilder AddSwaggerDocs(this IUkiyoBuilder builder, SwaggerOptions options) { if (!options.Enabled || !builder.TryRegister(RegistryName)) { return(builder); } builder.Services.AddSingleton(options); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc(options.Name, new OpenApiInfo { Title = options.Title, Version = options.Version }); if (options.IncludeSecurity) { c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); } }); return(builder); }
public static IUkiyoBuilder AddWebApi(this IUkiyoBuilder builder, Action <IMvcCoreBuilder> configureMvc, IJsonSerializer jsonSerializer = null, string sectionName = SectionName) { if (string.IsNullOrWhiteSpace(sectionName)) { sectionName = SectionName; } if (!builder.TryRegister(RegistryName)) { return(builder); } if (jsonSerializer is null) { var factory = new JsonSerializerFactory(StandardResolver.AllowPrivateCamelCase); JsonSerializer.SetDefaultResolver(new UkiyoFormatterResolver()); jsonSerializer = factory.GetSerializer(); } builder.Services.AddSingleton(jsonSerializer); builder.Services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); builder.Services.AddSingleton(new WebApiEndpointDefinitions()); var options = builder.GetOptions <WebApiOptions>(sectionName); builder.Services.AddSingleton(options); _bindRequestFromRoute = options.BindRequestFromRoute; var mvcCoreBuilder = builder.Services .AddLogging() .AddMvcCore(); mvcCoreBuilder.AddMvcOptions(o => { var resolver = CompositeResolver.Create(EnumResolver.Default, StandardResolver.AllowPrivateCamelCase); o.OutputFormatters.Clear(); o.OutputFormatters.Add(new JsonOutputFormatter(resolver)); o.InputFormatters.Clear(); o.InputFormatters.Add(new JsonInputFormatter(resolver)); }) .AddDataAnnotations() .AddApiExplorer() .AddAuthorization(); configureMvc?.Invoke(mvcCoreBuilder); builder.Services.Scan(s => s.FromAssemblies(AppDomain.CurrentDomain.GetAssemblies()) .AddClasses(c => c.AssignableTo(typeof(IRequestHandler <,>))) .AsImplementedInterfaces() .WithTransientLifetime()); builder.Services.AddTransient <IRequestDispatcher, RequestDispatcher>(); return(builder); }
public static IUkiyoBuilder AddRedis(this IUkiyoBuilder builder, RedisOptions options) { if (!builder.TryRegister(RegistryName)) { return(builder); } builder.Services.AddStackExchangeRedisCache(o => { o.Configuration = options.ConnectionString; o.InstanceName = options.Instance; }); return(builder); }