public static IMvcBuilder AddPostgRest(this IMvcBuilder builder, PostgRestOptions options = null) { options = builder.Services.EnsureOptions(options); builder.Services.AddPostgRest(options); var assembly = typeof(Extensions).GetTypeInfo().Assembly; return(builder .AddApplicationPart(assembly) .ConfigureApplicationPartManager(m => m.FeatureProviders.Add(new FeatureProvider(builder.Services, options))) .AddMvcOptions(o => { o.Conventions.Add(new ControllerConvention(options)); o.Conventions.Add(new ActionModelConvention()); })); }
public FeatureProvider(IServiceCollection services, PostgRestOptions options) { this.services = services; this.options = options; var dynamicAssemblyAssemblyName = new AssemblyName("PostgRest.net"); var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(dynamicAssemblyAssemblyName, AssemblyBuilderAccess.RunAndCollect); this.moduleBuilder = assemblyBuilder.DefineDynamicModule(dynamicAssemblyAssemblyName.Name); this.typeGet = typeof(GetController <>); this.typePost = typeof(PostController <>); this.typePut = typeof(PutController <>); this.typeDelete = typeof(DeleteController <>); using (var builder = this.services.BuildServiceProvider()) { logger = builder.GetService <ILogger <FeatureProvider> >(); } }
public ControllerConvention(PostgRestOptions options) { this.options = options; }
private static PostgRestOptions EnsureOptions(this IServiceCollection services, PostgRestOptions options) { if (options != null) { return(options); } var provider = services.BuildServiceProvider(); return(new PostgRestOptions(provider.GetRequiredService <IConfiguration>())); }
public static IServiceCollection AddPostgRest(this IServiceCollection services, PostgRestOptions options = null) { options = services.EnsureOptions(options); if (options.Connection != null) { services.AddScoped <NpgsqlConnection, NpgsqlConnection>(provider => { var config = provider.GetRequiredService <IConfiguration>(); var connStr = config.GetPgCloudConnectionString(options.Connection) ?? options.Connection; return(new NpgsqlConnection(connStr)); }); } services.TryAddScoped <IStringDataService, StringDataService>(); services.TryAddScoped <IStringContentService, StringContentService>(); services.TryAddScoped <ILoggingService, LoggingService>(); return(services); }