Improving ASP.NET MVC Routing Configuration β
This post covers some ways you can improve the testability and reduce framework coupling when configuring routing in an ASP.NET MVC application. π₯
https://t.me/pgimg/75
[ Article ] : http://bit.do/aspcr
γ°γ°γ°γ°γ°γ°
#AspMvc #Decoupling
@ProgrammingTip
This post covers some ways you can improve the testability and reduce framework coupling when configuring routing in an ASP.NET MVC application. π₯
https://t.me/pgimg/75
[ Article ] : http://bit.do/aspcr
γ°γ°γ°γ°γ°γ°
#AspMvc #Decoupling
@ProgrammingTip
Telegram
Programming Tips Resources
Why I am in love with ES6β
ES6 brings many new features to vanilla javascript making the language do more with less syntax. π₯
New features like let and fat arrows let us manage scope very easily too. ππ»
Some of ES6 new features π :
β’ Fat arrows
β’ Rest/Spread Operators
β’ Object Deconstruction
β’ Default Parameters
β’ import & export keywords
https://t.me/pgimg/76
[ Article ] : http://bit.do/es6
γ°γ°γ°γ°γ°γ°
#JavaScript #ES6
@ProgrammingTip
ES6 brings many new features to vanilla javascript making the language do more with less syntax. π₯
New features like let and fat arrows let us manage scope very easily too. ππ»
Some of ES6 new features π :
β’ Fat arrows
β’ Rest/Spread Operators
β’ Object Deconstruction
β’ Default Parameters
β’ import & export keywords
https://t.me/pgimg/76
[ Article ] : http://bit.do/es6
γ°γ°γ°γ°γ°γ°
#JavaScript #ES6
@ProgrammingTip
Telegram
Programming Tips Resources
Writing middleware for use in Express.js apps π₯
Overview π
Middleware functions are functions that have access to the request object (req), the response object (res), and the next function in the applicationβs request-response cycle.
The next function is a function in the Express router which, when invoked, executes the middleware succeeding the current middleware. β
Middleware can perform π
β’ Execute any code.
β’ Make changes to the request and the response objects.
β’ End the request-response cycle.
β’ Call the next middleware in the stack.
πΈπΉπΈπΉ
Configurable middleware π₯
If you need your middleware to be configurable, export a function which accepts an options object or other parameters, which, then returns the middleware implementation based on the input parameters.
πΈπΉπΈπΉ
Usage Middleware π€
The middleware can now be used as shown below.
https://t.me/pgimg/77
γ°γ°γ°γ°γ°γ°
#JavaScript #Express #Middleware
@ProgrammingTip
Overview π
Middleware functions are functions that have access to the request object (req), the response object (res), and the next function in the applicationβs request-response cycle.
The next function is a function in the Express router which, when invoked, executes the middleware succeeding the current middleware. β
Middleware can perform π
β’ Execute any code.
β’ Make changes to the request and the response objects.
β’ End the request-response cycle.
β’ Call the next middleware in the stack.
πΈπΉπΈπΉ
Configurable middleware π₯
If you need your middleware to be configurable, export a function which accepts an options object or other parameters, which, then returns the middleware implementation based on the input parameters.
in my-middleware.js
module.exports = function(options) {
return function(req, res, next) {
// Implement the middleware function
next();
}
}πΈπΉπΈπΉ
Usage Middleware π€
The middleware can now be used as shown below.
const mddleware = require('./my-middleware.js')
app.use(mddleware({ option1: '1', option2: '2' }))https://t.me/pgimg/77
γ°γ°γ°γ°γ°γ°
#JavaScript #Express #Middleware
@ProgrammingTip
Telegram
Programming Tips Resources
Fluent Validation β οΈ
A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules. π«
NuGet Packages :
For ASP.NET MVC integration :
For ASP.NET Core :
πΉπΈπΉπΈ
Example :
πΉπΈπΉπΈ
https://t.me/pgimg/78
[ Github ] : http://bit.do/flval
γ°γ°γ°γ°γ°γ°
#CSharp #AspMvc #Validation
@ProgrammingTip
A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules. π«
NuGet Packages :
Install-Package FluentValidation
For ASP.NET MVC integration :
Install-Package FluentValidation.MVC5
For ASP.NET Core :
Install-Package FluentValidation.AspNetCore
πΉπΈπΉπΈ
Example :
public class PersonValidator : AbstractValidator<Person>
{
public PersonValidator()
{
RuleFor(x => x.ID).NotEmpty();
RuleFor(x => x.FirstName)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.MinimumLength(5)
.WithMessage("Minimum length for {PropertyName} is {MinLength} !");
RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.MinimumLength(5)
.WithMessage("Minimum length for {PropertyName} is {MinLength} !");
RuleFor(x => x.Email)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.EmailAddress()
.WithMessage("{PropertyName} is not valid !");
}
}
πΉπΈπΉπΈ
https://t.me/pgimg/78
[ Github ] : http://bit.do/flval
γ°γ°γ°γ°γ°γ°
#CSharp #AspMvc #Validation
@ProgrammingTip
Telegram
Programming Tips Resources
Polly π
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. β»οΈ
Installing via NuGet π :
Usage :
We retry to send the email 3 times if something failed β :
πΉπΈπΉπΈ
https://t.me/pgimg/79
[ Github ] : http://bit.do/pollyc
γ°γ°γ°γ°γ°γ°
#CSharp #RetryPattern
@ProgrammingTip
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. β»οΈ
Installing via NuGet π :
Install-Package Polly
Usage :
public class Mailer
{
public static bool SendEmail()
{
Console.WriteLine("Sending Mail ...");
// simulate error
Random rnd = new Random();
var rndNumber = rnd.Next(1, 10);
if (rndNumber != 3)
throw new SmtpFailedRecipientException();
Console.WriteLine("Mail Sent successfully");
return true;
}
}
We retry to send the email 3 times if something failed β :
var policy = Policy.Handle<SmtpFailedRecipientException>().Retry(3);
policy.Execute(Mailer.SendEmail);
πΉπΈπΉπΈ
https://t.me/pgimg/79
[ Github ] : http://bit.do/pollyc
γ°γ°γ°γ°γ°γ°
#CSharp #RetryPattern
@ProgrammingTip
Telegram
Programming Tips Resources
Keyv π
Keyv provides a consistent interface for key-value storage across multiple backends via storage adapters. β‘οΈ
It supports TTL based expiry, making it suitable as a cache or a persistent key-value store. β°
By default everything is stored in memory, you can optionally also install a storage adapter. π
Supported Storage Adapters β :
β’ Redis
β’ Mongo
β’ SQLite
β’ Postgres
β’ MySQL
https://t.me/pgimg/80
[ Website ] : http://bit.do/keyv
γ°γ°γ°γ°γ°γ°
#JavaScript #KeyValue #Storage
@ProgrammingTip
Keyv provides a consistent interface for key-value storage across multiple backends via storage adapters. β‘οΈ
It supports TTL based expiry, making it suitable as a cache or a persistent key-value store. β°
By default everything is stored in memory, you can optionally also install a storage adapter. π
Supported Storage Adapters β :
β’ Redis
β’ Mongo
β’ SQLite
β’ Postgres
β’ MySQL
https://t.me/pgimg/80
[ Website ] : http://bit.do/keyv
γ°γ°γ°γ°γ°γ°
#JavaScript #KeyValue #Storage
@ProgrammingTip
Telegram
Programming Tips Resources
JavaScript - Map vs. ForEach πΊ
Whatβs the difference between Map and ForEach in JavaScriptβ
Letβs first take a look at the definitions on MDN π :
β’ forEach() β executes a provided function once for each array element.
β’ map() β creates a new array with the results of calling a provided function on every element in the calling array.
What exactly does this meanβ
https://t.me/pgimg/81
[ Article ] : http://bit.do/mapjs
γ°γ°γ°γ°γ°γ°
#JavaScript #ForEach #Map
@ProgrammingTip
Whatβs the difference between Map and ForEach in JavaScriptβ
Letβs first take a look at the definitions on MDN π :
β’ forEach() β executes a provided function once for each array element.
β’ map() β creates a new array with the results of calling a provided function on every element in the calling array.
What exactly does this meanβ
https://t.me/pgimg/81
[ Article ] : http://bit.do/mapjs
γ°γ°γ°γ°γ°γ°
#JavaScript #ForEach #Map
@ProgrammingTip
Telegram
Programming Tips Resources
dbForge Event Profiler β‘οΈ
dbForge Event Profiler for SQL Server is a FREE tool that allows you to capture and analyze SQL Server events. βοΈ
The events and data columns are stored in a physical trace file for later examination. π
You can use this information to identify and troubleshoot many SQL Server-related problems. π
https://t.me/pgimg/83
[ Download ] : https://t.me/pgimg/84
[ Website ] : http://bit.do/dbfor
γ°γ°γ°γ°γ°γ°
#SQLServer #Profiler #DbForge
@ProgrammingTip
dbForge Event Profiler for SQL Server is a FREE tool that allows you to capture and analyze SQL Server events. βοΈ
The events and data columns are stored in a physical trace file for later examination. π
You can use this information to identify and troubleshoot many SQL Server-related problems. π
https://t.me/pgimg/83
[ Download ] : https://t.me/pgimg/84
[ Website ] : http://bit.do/dbfor
γ°γ°γ°γ°γ°γ°
#SQLServer #Profiler #DbForge
@ProgrammingTip
Telegram
Programming Tips Resources
Passport.Js β‘οΈ
Passport is authentication middleware for Node.js.
Extremely flexible and modular, Passport can be unobtrusively dropped in to any Express-based web application. π₯
A comprehensive set of strategies support authentication using a username and password, Facebook, Twitter, and more. π¦
https://t.me/pgimg/85
[ Website ] : passportjs.org
γ°γ°γ°γ°γ°γ°
#JavaScript #NodeJs #Authentication
@ProgrammingTip
Passport is authentication middleware for Node.js.
Extremely flexible and modular, Passport can be unobtrusively dropped in to any Express-based web application. π₯
A comprehensive set of strategies support authentication using a username and password, Facebook, Twitter, and more. π¦
https://t.me/pgimg/85
[ Website ] : passportjs.org
γ°γ°γ°γ°γ°γ°
#JavaScript #NodeJs #Authentication
@ProgrammingTip
Telegram
Programming Tips Resources
Xamarin VS Ionic VS React Native π₯
Traditionally, Android applications are developed in Java, and iOS ones are written in Swift and Objective-C. βοΈ
Nevertheless, there exist plenty of other alternate tools that can be used instead. π¨π»βπ»
Xamarin, React Native and Ionic are popular examples of such tools. π
What is their purposeβ
What makes them differentβ
Which of them is the bestβ
Weβll try to answer these questions in the article below. β¬οΈ
https://t.me/pgimg/86
[ Article ] : http://bit.do/cpfo
γ°γ°γ°γ°γ°γ°
#Xamarin #ReactNative #Ionic
@ProgrammingTip
Traditionally, Android applications are developed in Java, and iOS ones are written in Swift and Objective-C. βοΈ
Nevertheless, there exist plenty of other alternate tools that can be used instead. π¨π»βπ»
Xamarin, React Native and Ionic are popular examples of such tools. π
What is their purposeβ
What makes them differentβ
Which of them is the bestβ
Weβll try to answer these questions in the article below. β¬οΈ
https://t.me/pgimg/86
[ Article ] : http://bit.do/cpfo
γ°γ°γ°γ°γ°γ°
#Xamarin #ReactNative #Ionic
@ProgrammingTip
Telegram
Programming Tips Resources
Quick Tip: How to pass visual alerts with an HTMLHelperβ οΈ
It will display a Bootstrap alert if there is a message passed through the ViewModel. π₯
This message can be a success, error, warning, or informational message. π
The nice thing about the ViewMessage HtmlHelper is that if we don't pass it into our views, it won't display anything. π
https://t.me/pgimg/87
[ Article ] : http://bit.do/alhl
γ°γ°γ°γ°γ°γ°
#AspMvc #CleanCode
@ProgrammingTip
It will display a Bootstrap alert if there is a message passed through the ViewModel. π₯
This message can be a success, error, warning, or informational message. π
The nice thing about the ViewMessage HtmlHelper is that if we don't pass it into our views, it won't display anything. π
https://t.me/pgimg/87
[ Article ] : http://bit.do/alhl
γ°γ°γ°γ°γ°γ°
#AspMvc #CleanCode
@ProgrammingTip
Telegram
Programming Tips Resources
Send ETag headers in ASP.NET Core β¨
ASP.NET Core doesnβt add an ETag header automatically to HTTP responses from MVC action methods or Razor Pages. β
We have to implement that ourselves to provide the users with true Conditional GET support that honors the If-None-Match request header. β
Wouldnβt it be nice if all we had to do was to register it using app.UseETagger() like thisβ
https://t.me/pgimg/88
[ Article ] : http://bit.do/etags
γ°γ°γ°γ°γ°γ°
#AspMvc #AspCore #ETag
@ProgrammingTip
ASP.NET Core doesnβt add an ETag header automatically to HTTP responses from MVC action methods or Razor Pages. β
We have to implement that ourselves to provide the users with true Conditional GET support that honors the If-None-Match request header. β
Wouldnβt it be nice if all we had to do was to register it using app.UseETagger() like thisβ
https://t.me/pgimg/88
[ Article ] : http://bit.do/etags
γ°γ°γ°γ°γ°γ°
#AspMvc #AspCore #ETag
@ProgrammingTip
Telegram
Programming Tips Resources
Automatic ModelState Validation in ASP.NET MVC π₯
How many times have you seen or written code like this β»οΈ :
Stop repeating ModelState checks in your ASP.NET MVC controller actions. β
Wouldnβt it be nice if all we had to do was like this ? β‘οΈ
https://t.me/pgimg/89
[ Article ] : http://bit.do/msta
γ°γ°γ°γ°γ°γ°
#AspMvc #CleanCode
@ProgrammingTip
How many times have you seen or written code like this β»οΈ :
[HttpPost]
public ActionResult Index(SomeModel model)
{
if (ModelState.IsValid)
{
return View();
}
// do something
return RedirectToAction("index");
}
Stop repeating ModelState checks in your ASP.NET MVC controller actions. β
Wouldnβt it be nice if all we had to do was like this ? β‘οΈ
[HttpPost]
[ValidateModelState]
public ActionResult Index(SomeModel model)
{
// if we get here, ModelState is valid
// save to db etc.
return RedirectToAction("index");
}
https://t.me/pgimg/89
[ Article ] : http://bit.do/msta
γ°γ°γ°γ°γ°γ°
#AspMvc #CleanCode
@ProgrammingTip
Telegram
Programming Tips Resources
The state of JavaScript in 2017 π₯
A few years back, a JavaScript survey would've been a simple matter.
Question 1 :
Are you using jQueryβ
Question 2 :
Any commentsβBoom, doneβοΈ
But as we all know, things have changed. β¨
The JavaScript ecosystem is richer than ever, and even the most experienced developer can start to hesitate when considering the multitude of options available at every stage.
There's data from over 20,000 developers, asking them questions on topics ranging from front-end frameworks and state management, to build tools and testing libraries. β
https://t.me/pgimg/90
[ Website ] : https://stateofjs.com
γ°γ°γ°γ°γ°γ°
#JavaScript #Analytics
@ProgrammingTip
A few years back, a JavaScript survey would've been a simple matter.
Question 1 :
Are you using jQueryβ
Question 2 :
Any commentsβBoom, doneβοΈ
But as we all know, things have changed. β¨
The JavaScript ecosystem is richer than ever, and even the most experienced developer can start to hesitate when considering the multitude of options available at every stage.
There's data from over 20,000 developers, asking them questions on topics ranging from front-end frameworks and state management, to build tools and testing libraries. β
https://t.me/pgimg/90
[ Website ] : https://stateofjs.com
γ°γ°γ°γ°γ°γ°
#JavaScript #Analytics
@ProgrammingTip
Telegram
Programming Tips Resources
How we do MVC β View models π
The ViewModel is a central aspect of our MVC architecture. π
One of the first dilemmas facing MVC developers is to decide what the βMβ in MVC means in ASP.NET MVC. π€
In Rails, this is fairly clear, the M is ActiveRecord (by default). π
But in ASP.NET MVC, the βMβ is silentβοΈ
Its out-of-the-box architecture offers no guidelines nor advice on what the M should be. βοΈ
Should it be an entityβ
Data access objectβ
DTOβ
Something elseβ
https://t.me/pgimg/91
[ Website ] : http://bit.do/mvvm
γ°γ°γ°γ°γ°γ°
#AspMvc #CleanCode #BestPractices
@ProgrammingTip
The ViewModel is a central aspect of our MVC architecture. π
One of the first dilemmas facing MVC developers is to decide what the βMβ in MVC means in ASP.NET MVC. π€
In Rails, this is fairly clear, the M is ActiveRecord (by default). π
But in ASP.NET MVC, the βMβ is silentβοΈ
Its out-of-the-box architecture offers no guidelines nor advice on what the M should be. βοΈ
Should it be an entityβ
Data access objectβ
DTOβ
Something elseβ
https://t.me/pgimg/91
[ Website ] : http://bit.do/mvvm
γ°γ°γ°γ°γ°γ°
#AspMvc #CleanCode #BestPractices
@ProgrammingTip
Telegram
Programming Tips Resources
Working With Zip Files In ASP.NET MVC π
Since ASP.NET 4.5, zipping and unzipping files can be done with classes from within the .NET framework. π
Despite that, nearly all examples that illustrate working with zip files in ASP.NET applications feature third party open source compression libraries. πΎ
This short article attempts to correct that by demonstrating the use of the System.IO.Compression classes in an ASP.NET MVC application to β :
1οΈβ£ Unpack an uploaded zip file
2οΈβ£ Create one for download
https://t.me/pgimg/92
[ Article ] : http://bit.do/aspzip
γ°γ°γ°γ°γ°γ°
#AspMvc #Compression
@ProgrammingTip
Since ASP.NET 4.5, zipping and unzipping files can be done with classes from within the .NET framework. π
Despite that, nearly all examples that illustrate working with zip files in ASP.NET applications feature third party open source compression libraries. πΎ
This short article attempts to correct that by demonstrating the use of the System.IO.Compression classes in an ASP.NET MVC application to β :
1οΈβ£ Unpack an uploaded zip file
2οΈβ£ Create one for download
https://t.me/pgimg/92
[ Article ] : http://bit.do/aspzip
γ°γ°γ°γ°γ°γ°
#AspMvc #Compression
@ProgrammingTip
Telegram
Programming Tips Resources
ASP.NET MVC Best Practices and Guidelines β
While most developers were used to WebForms and Microsoft's stock controls, when developers moved to ASP.NET MVC, a number of developers were shocked because there wasn't enough meat for this to be a full-featured release. π€
Some of the guidelines list below are based on my own experiences over the years since 2008. π
https://t.me/pgimg/93
[ Website ] : http://bit.do/aspbst
γ°γ°γ°γ°γ°γ°
#AspMvc #CleanCode #BestPractices
@ProgrammingTip
While most developers were used to WebForms and Microsoft's stock controls, when developers moved to ASP.NET MVC, a number of developers were shocked because there wasn't enough meat for this to be a full-featured release. π€
Some of the guidelines list below are based on my own experiences over the years since 2008. π
https://t.me/pgimg/93
[ Website ] : http://bit.do/aspbst
γ°γ°γ°γ°γ°γ°
#AspMvc #CleanCode #BestPractices
@ProgrammingTip
Telegram
Programming Tips Resources
Auth0: Introduction and Initial ASP.NET MVC Project Setup π
The big selling points for Auth0, and other services like it, are that it removes you from having to worry about Auth/User Management and get to the part of your applications that bring value to your customers. π₯
As with Identity Server, Auth0 can use OpenID Connect (as well as a lot of other protocols), single sign-on and API Access Control. β
https://t.me/pgimg/94
[ Article ] : http://bit.do/auas
γ°γ°γ°γ°γ°γ°
#AspMvc #Auth0 #Authentication
@ProgrammingTip
The big selling points for Auth0, and other services like it, are that it removes you from having to worry about Auth/User Management and get to the part of your applications that bring value to your customers. π₯
As with Identity Server, Auth0 can use OpenID Connect (as well as a lot of other protocols), single sign-on and API Access Control. β
https://t.me/pgimg/94
[ Article ] : http://bit.do/auas
γ°γ°γ°γ°γ°γ°
#AspMvc #Auth0 #Authentication
@ProgrammingTip
Telegram
Programming Tips Resources