asp.net core

Lazy-loading NgModules in ASP.NET Core AngularSPA

Angular has this cool feature of loading a module lazily. Modules that are set up to load lazily can significantly save application startup time. Lazy-load module set up is done in application's routing configuration section. As the title suggests we will be using the AngularSPA template shipped with Visual Studio 2017 Preview (2) for demonstration. Route that is configured to lazy-load a module sends an HTTP GET to the server which in turns return the module in a chunk of code block. This only happens when the router is activated…

Keep reading

Cache headers for MVC File Action Result (ASP.NET Core 2.0 Preview 2)

You typically work with one of the following action results when you want to write a file to the response. FileContentResult (writes a binary file to response) FileStreamResult (writes a file from a stream to the response) VirtualFileResult (writes a file specified using a virtual path to the response) These are all coming from ASP.NET Core's MVC package. In earlier version of ASP.NET Core (1.*); using these action results, you could have served files but there wasn't any way of configuring cache headers for the responses. I'm pretty…

Keep reading

Entity Framework Core Triggers in Action (Unofficial Package)

Recently I have had this problem of updating a field of an entity that is dependent on another field of another entity. Confused already? Let me give you an example: so, I've these Inventory and Item entities where there exists a many-to-many relation between them. So, of course there should also be a relation table between them i.e. InventoryItem. The problem I was having actually is I have had this one field called CurrentQuantity on the Item entity and other called IssuedQuantity on the relation table (InventoryItem). Thus, as…

Keep reading

ASP.NET Core API Versioning in Simple Words (Update 1.2.0)

Few days ago, me and my friends developed an API using ASP.NET Core where from the GET method we returned some data to our client app. We did pagination in the front end. Means that first we sent all the data to the client and then did some data.length operation on that to get the items count for applying pagination logic. Then decided that we should do the logic in the back-end (server-side pagination) because it will decrease the payload of the HTTP request. In our case it…

Keep reading

Terms we don't fully understand while learning ASP.NET core

There are some terms, developers like me often ignore while learning ASP.NET Core. Because at the end of the day it's all about making apps not learning stuff. But having a basic understanding over the core concepts can make you a lot better developer than you already are. So, this article will clear the concepts of some of those ignored and misunderstood terms in details. This article is upgradable with new topics. So, if you have other topics such as below and want it here, please make a comment…

Keep reading

Adding Angular Material in ASP.NET Core Angular SPA template (Bonus : Animations)

If you are not familiar with ASP.NET Core SpaServices, take a look at this repository: https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices Lots of SPA templates (Angular, React, Vue, Aurelia etc.) are available in this repo that uses NodeServices for server side rendering. We will work with the AngularSpa template and add Angular Material in it. To install the Spa templates via yeoman, first intall the template generator with the following command: npm install -g generator-aspnetcore-spa@next Create a directory where you will initialize the…

Keep reading

Execute javascript code from ASP.NET Core back-end using NodeServices

Not many are familiar with this awesome feature of dotnet core. Aspnet team is actively maintaining a project named JavascriptServices; Along with other packages, it includes the NodeServices package. Using this package, one can easily create an instance of node and execute javascript code (function) in the backend. If you think of it right now, you can see that it actually opens up a wide variety of development opportunities. By opportunities I mean; the asp.net core project is trying hard to make its package eco-system (NuGet) rich but while…

Keep reading

Building Custom Formatters for .Net Core (Yaml Formatters)

Quite recently I got myself introduced to .net core’s formatters. In short, what formatters do is format your response and request in your preferred data formats. For example, Json formatters, if used would format your response (returned value from controller's action) and request (value passed as a parameter to the controller) in Json. Same goes for the XML and other formatters. .Net Core gives you some formatters out of the box. This official documentation link described them briefly https://docs.microsoft.com/en-us/aspnet/core/mvc/models/formatting But…

Keep reading

Dependency Injection to The Core (Part - III)

We came to know about the term IoC container. There are many IoC containers available and most of them do the same things somewhat differently. Let’s use one of them in our current project. Let’s pick Autofac which has a great documentation online. Here is the link where you can know all about the Autofac integration related stuff with Web API projects, http://autofac.readthedocs.io/en/latest/integration/webapi.html Since we are just beginners wondering around the world of dependency injection. We will go slow and…

Keep reading

Dependency Injection to The Core (Part - II)

Say for example, our client changed their requirements and now wants us to read and write comma separated data (CSV) from a filesystem instead of a database. Suppose I’ve searched and downloaded a cool library that can work with CSV files. So, we have a CSV library configured and ready to talk with our CSV files in the data access layer. If you are following me then you would say, now that we have a new data access layer, we also need a new repository. Right? Exactly! Since we…

Keep reading