/// <summary> /// Entry point. /// </summary> /// <param name="args">Arguments passed in.</param> /// <returns>A <see cref="Task"/> for asychronous processing.</returns> public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("app"); builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); // this adds the client with the base address to post to /efcore/{context}/{collection} builder.Services.AddExpressionPowerToolsEFCore(new Uri(builder.HostEnvironment.BaseAddress)); if (builder.HostEnvironment.IsDevelopment()) { QueryExprSerializer.ConfigureDefaults(config => config.CompressTypes(false)); } // this adds a helper class for composing the query builder.Services.AddScoped( sp => new RemoteQueryClientService()); await builder.Build().RunAsync(); }
/// <summary> /// Main configuration method for Power Tools EF Core middleware. /// </summary> /// <param name="endpointRouteBuilder">The <see cref="IEndpointRouteBuilder"/>.</param> /// <param name="pattern">The pattern for the route (defaults to <c>/efcore</c>).</param> /// <param name="dbContextTypes">The list of <c>DbContext</c> types to support.</param> /// <param name="rules">The <see cref="IRulesConfiguration"/> to configure serialization rules.</param> /// <param name="noDefaultRules">Determines whether the default rule set should be applied.</param> /// <param name="options">The <see cref="IConfigurationBuilder"/> to configure options.</param> /// <returns>The <see cref="IEndpointConventionBuilder"/>.</returns> public static IEndpointConventionBuilder MapPowerToolsEFCore( this IEndpointRouteBuilder endpointRouteBuilder, RoutePattern pattern, Type[] dbContextTypes, Action <IRulesConfiguration> rules = null, bool noDefaultRules = false, Action <IConfigurationBuilder> options = null) { Ensure.NotNull(() => endpointRouteBuilder); Ensure.NotNull(() => pattern); Ensure.NotNull(() => dbContextTypes); if (pattern.Parameters.Count != 2) { throw new ArgumentException( $"{DefaultPattern}<~>{pattern.RawText}", nameof(pattern)); } if (!pattern.Parameters.Any(p => p.Name == Context)) { throw new ArgumentException(Context, nameof(pattern)); } if (!pattern.Parameters.Any(p => p.Name == Collection)) { throw new ArgumentException(Collection, nameof(pattern)); } if (dbContextTypes.Length == 0) { throw new ArgumentException( $"{nameof(dbContextTypes)}.Length = 0", nameof(dbContextTypes)); } var badType = dbContextTypes.FirstOrDefault( t => !typeof(DbContext).IsAssignableFrom(t)); if (badType != null) { throw new ArgumentException( $"{badType} != {typeof(DbContext)}", nameof(dbContextTypes)); } // passed tests, check configuration if (options != null) { QueryExprSerializer.ConfigureDefaults(options); } if (rules != null || noDefaultRules == true) { QueryExprSerializer.ConfigureRules(rules, noDefaultRules); } var appBuilder = endpointRouteBuilder.CreateApplicationBuilder(); appBuilder.UseMiddleware <ExpressionPowerToolsEFCoreMiddleware>( pattern.RawText, dbContextTypes); return(endpointRouteBuilder.Map(pattern, appBuilder.Build()) .WithDisplayName($"Expression Power Tools Serialization Pipeline")); }
public QueryExprSerializerTests() { QueryExprSerializer.ConfigureDefaults( config => config.CompressExpressionTree(false)); }