ASP.NET Core 3 Service…

ASP.NET Core 3 Service Registration – AddControllers() AddControllersWithViews() AddRazorPages()

With v3 and higher, there are several ways to register MVC. This way the application can only use what it requires, not the whole framework. This would result with a smaller size and being not sure, better performance.

AddControllers()

If you are developing an API, go with this. This is only for API-related features, Views or pages are not supported.

AddControllersWithViews();

This adds API + Views but not Pages. If you “dotnet new mvc”, it uses this code.

AddRazorPages()

This adds support for Razor Pages and minimal controller support. If you “dotnet new web”, it uses this code.

These can be combined as well. The following is equivalent to calling AddMvc in ASP.NET Core 2.2:

  
services.AddControllersWithViews();
services.AddRazorPages();

Resources:

https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio-code#mvc-service-registration

https://www.strathweb.com/2020/02/asp-net-core-mvc-3-x-addmvc-addmvccore-addcontrollers-and-other-bootstrapping-approaches/

#aspnetcore #dotnet #net-core

BigQuery with .NET Core

Here is a sample respository ready to be injected to a ASP.NET Core application.

   public class SelfViewRepository : ISelfViewRepository
    {
        private readonly string _projectId;
        private readonly GoogleCredential _gcpCredential;

        public SelfViewRepository(string projectId, string credentialFile)
        {
            _projectId = projectId;
            _gcpCredential = GoogleCredential.FromFile(credentialFile);
        }

        public async Task<BigQueryResults> GetData(string query)
        {
            BigQueryClient client = BigQueryClient.Create(_projectId, _gcpCredential);

            BigQueryJob job = client.CreateQueryJob(
                sql: query,
                parameters: null,
                // options: new QueryOptions {UseQueryCache = false});
                options: new QueryOptions { });
            var data = await job.GetQueryResultsAsync();
            // Wait for the job to complete.
            job.PollUntilCompleted();
            // Display the results
            return data;
        }
    }

#googlecloud #bigquery #aspnetcore