Advantages of .Net Core, ASP.NET Core, EF Core

In this post I would like to List down the Advantages of .Net Core, ASP.NET Core, EF Core.

.Net Core Advantages

Open Source allowing source code availability & customization.

Cross-Platform runs on Windows, Linux and Mac OS.

Lightweight through newly written libraries, no dependency on windows OS libraries

High Performance in speed & efficiency

Scalability possible through Microservices & Containers supporting architecture

Disadvantages Third party library support are limited, Not available in Desktop applications.

ASP.NET Core Advantages

Additional to the open-source, cross-platform, light-weight advantages of .Net Core, following are the advantages of ASP.NET Core.

Unified story for building Web UI & Web APIs.

Testability friendly architecture through support for Interfaces.

Built-in Dependency Injection allowing singleton, scope, transient instance creation.

Host Friendly allowing hosting in IIS, Apache & Other web servers

Cloud-ready enabled for Azure, AWS hosting

EF Core Advantages

Additional to the open-source, cross-platform, light-weight advantages of .Net Core, following are the advantages of EF Core.

Batch Updates for sending multiple queries to the database thus reducing roundtrips & enhancing performance.

Alternate Keys support along with primary key.

In-Memory Provider for holding all entities in memory useful for unit testing.

Shadow Properties are those which are not in the entity class but tracked in the Change Tracker.

Mixing FromSQL with LINQ allowing SELECT * FROM statement mix with OrderBy() LINQ queries.

Note

All Core projects are complete re-write of the same.

Microservices, Advantages, Applications, Overheads

Microservices is a Hot Trend in the Industry. Everyone knows the Advantages of it.  Here I would like to list down the same.

Microservices

Microservices are small services, with clear boundaries, easily deployable without affecting other components & offering individual scalability.

Microservices have their own code & data within them.

Microservices offer freedom of technology choices.

Advantages

  • small services
  • single responsibility
  • separate processes
  • clear boundaries
  • easily deployable
  • individually scalability

Applications

NetFlix is a well known example of implementing Microservices.  Here the Netflix contains of following Microservices:

  • Public Website
  • Authentication
  • User Registration
  • Movie Selection
  • Streaming
  • New Releases

Here if each of this is considered as individual microservice, it can be developed, modified, deployed & scaled separately without affecting other application boundaries.

Overheads

But give the advantages, I have never seen a 100% microservice application myself.  Each & Every architect claims to have implemented Microservices.  But when we dig deeper there are missing parameters to support the full microservice implementation.

Boundaries All the depending modules need to have clear boundaries of code & data.  If one of the code/data depends on your microservice module then it will cause failure.

Asynchronous All the synchronous calls has to be converted to asynchronous calls.  For this a normal API call needs to be migrated to Service Bus Messages given an Azure scenario.

Repositories Since each microservice has its own code & data, we need to maintain separate code repositories for each.

Debugging Overheads Unlike monolithic application where one can press F5 and debug a button click to service, it is not possible with microservice.  More complexity is there in debugging microservices.

Azure Functions 2.0

In this article we can explore about Azure Functions & Latest release 2.0.

Azure Functions

Azure Function is a serverless compute service. It allows to quickly create a Function & Deploy to Azure Cloud without worrying about the Infrastructure. It has features like Auto-Scale, Pay-per-Use Pricing model, Multiple Language Support, Multiple Triggers, Integrated Security etc.

In short Azure Functions is Event + Code, Serverless, FaaS.

image

Serverless does not mean there are No Servers. But, they Scale easily to N number of Hardware depending on the Load.

Azure Functions 2.0

Following are the New Features in Azure Functions 2.0:

· Cross-Platform Support

· .Net Core 2.1 Support

· Non .Net Language Support

· Native Tooling Support

· Increased DevOps Support

· Consumption based Billing

image

Azure Functions in its Totality is better than Azure Web Jobs.

Consumption Plan

Consumption Plan gives the Flexibility that You will be Charged only the Execution Time of Functions.

Where to use Functions?

We can use Functions in Once-in-a-While scenarios like:

  • Tax Calculations during Tax Period which requires heavy-use, easier-scalability
  • Data Processing Period during a Client Engagement where Data Processing will be done in a day & rest of the time only reporting will be used

Native Tooling in Visual Studio 2017

Visual Studio 2017 includes the Azure Functions SDK to provide Functions template.

image

References

https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview

https://azure.microsoft.com/en-us/blog/introducing-azure-functions-2-0/

Summary

In this article we have explored about Azure Functions 2.0.

RESTful Operations – The Most Perfect CRUD Operations!

As you know, HTTP is RESTful Protocol with the HTTP Verbs meant for CRUD mapping initially.

But I am seeing may Wrong Doings in Implementation like:

  • Wrong HTTP Method for Operation
  • Wrong Naming Conventions

Perfect Mapping

Here I would like to Map in the Perfect Way recommended by Microsoft.

  • CREATE operation can be mapped to POST
  • READ operation can be mapped to GET
  • UPDATE operation can be mapped to PUT
  • DELETE operation can be mapped to DELETE

Note

CREATE is essentially mapped to POST and Visual Studio Code Generation also recommends same.

Example

Here I am creating a CRUD Controller with the above Method Representations.

    [Route(“api/[controller]”)]
public class EmployeeController : Controller
{
private static IDictionary<int, string> _list = new Dictionary<int, string>();

public EmployeeController()
{
if (_list.Count == 0)
{
_list.Add(1, “Amar”);
_list.Add(2, “Akbar”);
_list.Add(3, “Antony”);
}
}

// GET: api/<controller>
         [HttpGet]
public IEnumerable<string> Get()
{
return _list.Values;
}

// GET api/<controller>/5
         [HttpGet(“{id}”)]
public string Get(int id)
{
string result = string.Empty;

_list.TryGetValue(id, out result);

return result;
}

// POST api/<controller>
         [HttpPost]
public void Post([FromBody]string value)
{
_list.Add(_list.Keys.Max() + 1, value);
}

// PUT api/<controller>/5
         [HttpPut(“{id}”)]
public void Put(int id, [FromBody]string value)
{
_list[id] = value;
}

// DELETE api/<controller>/5
         [HttpDelete(“{id}”)]
public void Delete(int id)
{
_list.Remove(id);
}
}

Execution

On execution we can play with Postman against the same Controller Name and changing the HTTP Verbs.

image

Following are the actual UI screenshots.

List

image

Insert

image

Update

image

Delete

image

Design Guidelines

  • Do not expose Database Structure through APIs.
  • Avoid Chatty API Requests which will degrade the performance
  • Asynchronous operations gives better Client experience.  Return 202 status & Provide Monitor URL for observing the status.
  • Use Pagination to optimize usage of resources – especially in PaaS style programming where Cost depends on the usage.
  • Limit the return Field parameters to optimize traffic
  • Use HATEOS inside responses which are Links to the subsequent operations which helps Navigating around all the operations associated with the resources
  • Implement Versioning so new APIs can be supported without affecting the existing clients

References

https://azure.microsoft.com/mediahandler/files/resourcefiles/api-design/Azure_API-Design_Guide_eBook.pdf

Summary

The reason I call his the Most Perfect CRUD operations is because the same controller name is used for all the 4 operations.