Recently I have been assigned to start a new software project for one of the clients. In this post I have shared my experience on choosing the technology and the strategy. But I would not be possible to disclose the business area of which this software will be used for, to keep the confidentiality. As I was the technical lead, none other than me had to do the crucial sophisticated job, had to start the ball rolling, and had to wrap up everything. It was okay, I enjoyed, doing this often. Every time I had to research and then have to choose latest stable technology stack depending business needs. Also had to take a decision and had to validate my decision.
Technology Stack
I have chosen .Net Core Web API with the Angular front end. But for some obvious reason I have not use .Net default Angular templet. I have separated the projects from each other. Also have chosen Ionic as there was a small part which meant to be a mobile application. So it might be possible to write code using Ionic or to serve the web view via ionic. As there was open Web API I have had the security on mind and have left the communicative security part for the later. And have chosen MongoDB as database, probably would take the benefit to host in Azur CosmosDB later, following some real lucrative staff of the Cosmos DB in recent days. And for caching I have used RedisDB.
According to the business needs the way I have designed, there also had two more extension and for one of the extension I chose as usual .Net Core MVC and MariaDB for the database. The other one was just a console application connected with the same MariaDB of the first extension and with the API of the main application.
Team
After on boarding I have set people in following team
Angular | Team A |
Web API + MongoDB + API Testing | Team B |
Ionic | Team C |
.Net Core MVC + MariaDB | Team D |
.Net Core Console | Team E |
Angular/UI Testing | Team F |
Technical Writing | Team G |
For the project management I normally use Jira and there was no exception this time.
Architecture/ High Level Design
I have described on each topics of the technology used to start. And so far I have decided to divide the blogs in following series
- Starting (This Article) – I have already explained the brief introduction, and also going conclude the setting up the Project of Web API
- Database Connectivity- In this article I will describe the way to establish connectivity with Mongo and Redis and probably at set of strategy.
- Front End – Setting up Angular Project and connectivity with the API will be explained.
- API Testing – I will be discussing regarding some tools to be used for API testing.
- UI Testing – I will explore some UI Testing tools to test the Angular UI.
- DevOps – Some option to integrate continues integration will be explored.
Web API
Let’s create a new the Web API project using VS2017. I have named it as “Example”. As usual the project will be found at GitHub repository.
It has given us the following files. Let’s navigate to value controller and inspect.
After running it serves in the following URL
https://localhost:44352/api/values.
If noticed, there is https because the https option was checked when the project was created. A new option of the update. At the startup.cs a new line appeared
1 2 3 |
app.UseHttpsRedirection(); |
For the purpose of the demo to be used in this article I have used the value controller. So getting rid of all the default code my controller looks like this
1 2 3 4 5 6 7 8 9 |
namespace Example.Controllers { [ApiController] public class ValuesController : Controller { } } |
As the URL was served prefixing “value” I have changed that to the default route by including an attribute “[Route(“[controller]”)]” at the top of “[ApiController]”. Have created a simple
1 2 3 4 5 6 7 |
public class MyClass { public int ID { get; set; } public int MyProperty { get; set; } } |
And then added a few code in the controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[Route("[controller]")] [ApiController] public class ValuesController : Controller { [HttpGet] [Route("[action]")] public async Task<JsonResult> Hello(int id = 0) { var x = new MyClass { ID = id, MyProperty = "x" }; return Json(x); } } |
Then the JSON object is retrievable my calling “https://localhost:44352/values/Hello” after we run the application. And I am good to go with the basics.
Logging
To get the logging I have added a constructor for the logger to be injected in the controller and added a “ILogger” variable.
1 2 3 4 5 6 7 |
private readonly ILogger _logger; public ValuesController(ILoggerFactory loggerFactory) { _logger = loggerFactory.CreateLogger<ValuesController>(); } |
And in the Configuration section, have added the following line after add logging service and the parameter.
1 2 3 |
loggerFactory.AddConsole(Configuration.GetSection("Logging")); |
So the logger is in place and can be called from the action methods of the controller.
Swashbuckle
With this I do not need to use the Postman anymore. It automatically configure the page to test the APIs of our application. Have added that using
1 2 3 |
dotnet add package Swashbuckle.AspNetCore --version 4.0.1 |
Then have added following to the “ConfigureService” and “Configure” method of the startup.cs
1 2 3 |
services.AddSwaggerGen(x => x.SwaggerDoc("V1.0", new Info { Title = "Signature", Version = "V1.0" })); |
and
1 2 3 4 5 6 7 |
app.UseSwagger(x => x.RouteTemplate = "api/{documentName}/swagger.json"); app.UseSwaggerUI(x => { x.SwaggerEndpoint("/api/V1.0/swagger.json", "API V1.0"); x.RoutePrefix = string.Empty; }); |
So the swagger is all set we are good to with that.
Conclusion
So far that is it. As I realized that there are always something which I could not explain why I have done that because then had to write so many things in that case. Like I could easily write one big article on Swashbuckle. I have chosen to write the blogs to share my experiences rather than actual tutorial purpose. But feeling like some things are blurred the way I am writing, so have decided to publish some videos with the next blogs. So I will target to provide a video with each of my blog from the next video. The solution can be found on Git.