/// <summary> /// Adds Seltzr middleware with Entity Framework to the app /// </summary> /// <typeparam name="TModel">The type of model to use with the API</typeparam> /// <typeparam name="TContext">The type of database context to use to access <typeparamref name="TModel"/> entities</typeparam> /// <typeparam name="TUser">The user to authenticate with the API</typeparam> /// <param name="app">The app to add Seltzr to</param> /// <param name="route">The base route for Seltzr</param> /// <param name="optionsHandler">A handler to set options for this Seltzr API</param> /// <param name="routeOptionsHandler">A handler to set ASP.NET Core options</param> /// <returns>The same <see cref="IApplicationBuilder" />, for chaining</returns> public static IApplicationBuilder AddEFCoreSeltzr <TModel, TContext, TUser>( this IApplicationBuilder app, string route, Action <SeltzrOptionsBuilder <TModel, TUser> > optionsHandler, Action <IEndpointConventionBuilder>?routeOptionsHandler) where TModel : class where TContext : DbContext where TUser : class { SeltzrOptionsBuilder <TModel, TUser> OptionsBuilder = new EntityFrameworkSeltzrOptionsBuilder <TModel, TUser>(app, typeof(TContext), route, routeOptionsHandler); OptionsBuilder.UseModelProvider(new EntityFrameworkModelProvider <TModel, TContext>()); optionsHandler(OptionsBuilder); return(app.AddSeltzr(OptionsBuilder.BuildAll())); }
/// <summary> /// Adds Seltzr middleware with Entity Framework to the app /// </summary> /// <typeparam name="TModel">The type of model to use with the API</typeparam> /// <typeparam name="TContext">The type of database context to use to access <typeparamref name="TModel"/> entities</typeparam> /// <typeparam name="TUser">The user to authenticate with the API</typeparam> /// <param name="app">The app to add Seltzr to</param> /// <param name="route">The base route for Seltzr</param> /// <param name="optionsHandler">A handler to set options for this Seltzr API</param> /// <param name="routeOptionsHandler">A handler to set ASP.NET Core options</param> /// <param name="primaryKeyProperties">An array of properties that make up the primary key. If omitted, the primary key will be determined automatically</param> /// <returns>The same <see cref="IApplicationBuilder" />, for chaining</returns> public static IApplicationBuilder AddEntityFrameworkSeltzr <TModel, TContext, TUser>( this IApplicationBuilder app, string route, Action <SeltzrOptionsBuilder <TModel, TUser> > optionsHandler, Action <IEndpointConventionBuilder>?routeOptionsHandler, params Expression <Func <TModel, object> >[] primaryKeyProperties) where TModel : class where TContext : DbContext where TUser : class { List <PropertyInfo>?PrimaryKey = primaryKeyProperties.Length == 0 ? null : primaryKeyProperties.Select( EntityFrameworkSeltzrApplicationBuilderExtensions .ExtractProperty) .ToList(); SeltzrOptionsBuilder <TModel, TUser> OptionsBuilder = new EntityFrameworkSeltzrOptionsBuilder <TModel, TUser>(app, typeof(TContext), PrimaryKey, route, routeOptionsHandler); OptionsBuilder.UseModelProvider(new EntityFrameworkModelProvider <TModel, TContext>()); optionsHandler(OptionsBuilder); return(app.AddSeltzr(OptionsBuilder.BuildAll())); }