Blazor WebAssembly support

Ventura SQL 3.0 with full support for Blazor WebAssembly will be available for download next week.

Ventura SQL is the 3-tier SQL framework for C# projects where database access and web services are integrated into a fully integrated solution. Ventura replaces Web API and Entity Framework. Just enter SQL statements and Ventura will do the rest.

Ready-to-run sample Client and Server projects are included.

Ventura SQL Studio


The challenge in making Ventura SQL compatible with Blazor WebAssembly is the .Net HttpClient class that needs to be used for sending HTTP requests to a server.

From a Blazor WebAssembly app you cannot simply create a new instance of the HttpClient class and use it to access the server. The HttpClient in Blazor WebAssembly is implemented using the browser Fetch API and is subject to its limitations, including enforcement of the same origin policy.

For this reason a HttpClient instance can only be created by the Blazor runtime. Blazor will instantiate and configure the HttpClient to run in the sandbox environment of the browser.

In a Razor Page a HttpClient instance must be requested using the @inject statement, in the page’s code-behind the [Inject] attribute is used.

Using the dependency injection solution means that the Ventura SQL API would need to change to accept a HttpClient as a parameter instead of instantiating one itself. In order to keep the Ventura API uniform across all platforms an elegant solution was found. Whenever Ventura needs a HttpClient instance it calls a user defined method that is expected to return a proper HttpClient object. The method is assigned with VenturaConfig.SetHttpClientFactory(). Inside that method Blazor WebAssembly is asked for a HttpClient instance.

The sample Program class code below explains it all.

    public class Program
        private static ServiceProvider _service_provider;

        public static async Task Main(string[] args)
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });


            await builder.Build().RunAsync();

        private static void SetupVentura(WebAssemblyHostBuilder builder)
            _service_provider = builder.Services.BuildServiceProvider();
            VenturaConfig.DefaultConnector = new HttpConnector("test", $"{builder.HostEnvironment.BaseAddress}Ventura.FSPRO");

        private static HttpClient GetHttpClientForVenturaSQL(HttpConnector connector)
            var client = _service_provider.GetService(typeof(HttpClient)) as HttpClient;
            return client;