mercredi 28 septembre 2016

NLayered Architecture



When we start any project,  we have to think about the architecture and use the best practices and avoid the anti-pattern (http://hamidarebai.blogspot.it/2016/03/do-you-like-spaghetti-or-lasagna.html) ,  To achieve layered architecture, ASP.NET  we have to follows the principles of Domain Driven Design. In Domain Driven Design there are four fundamental layers:

1- Infrastructure Layer : this layer is used to interact with Database using ORM framework,  like NHibernate or Entity Framework, it can be a Repository implementation or an implementation for an email provider to send emails.
2-Domain Layer : in this layer we find  business objects and their rules . This is the core of the application, it contain : entities, value objects, repositories, domain services, Unit of Work, Domain Events...
3- Application Layer : Interaction layer between the Presentation and Domain Layers. Orchestrates business objects to perform specific application tasks, we can use DTOs, DTO Mappers, Authorization, Session, Audit Logging...
4- Presentation Layer : that can present SPA or MVC or MVVM  web application, it's the user interface , the front-end part of any application and can be a mobile interface too. We can add in this layer : Localization, Navigation, Notifications...

We can use another Layer to expose services : WCF or Web API .
In presentation layer, we can use Web API Controllers integrated in Core web project .

jeudi 22 septembre 2016

Building A RESTFUL API with ASP.NET CORE and Visual Studio 2015


To start your environment, please refer to this article : http://hamidarebai.blogspot.it/2016/07/how-we-can-start-using-visual-studio_22.html

So, we consider that everything is set.

This a video that describe all :
And the source code :

mardi 20 septembre 2016

Difference between SOAP and REST Web Services (from generic to .NET)




SOAP
REST
Acronyme
Simple Object Access Protocol
REpresentational State Transfer
Architecture
SOA based architecture that use middleware interoperability.
Architecture style protocol designed for web based communication assuming only point to point communication.
Message Format
XML inside a SOAP Envelope
XML
In business logic
Uses services interfaces to expose the business logic.
Uses URI to expose business logic.
Standards
Defines standards to be strictly followed.
Does not define too much standards like SOAP.
Communication
Use WSDL for communication between consumer and provider.
Uses XML or JSON to send and receive data.
Transport
Transfer is over HTTP, Also uses other protocols such as SMTP, FTP, MIME, JMS, HHTP, etc.
Transfer is over HTTP only.
JavaScript calls
JavaScript can call SOPA but it is difficult to implement.
Easy to call from Javascript.
Security
SOAP defines its own security.
RESTful web services inherits security measures from the underlying transport.
Payload
Payload must support SOAP schema.
Payload can be of any format.
Error Handling
Doesn't support error handling.
Has built-in error handling.
External Calls
Invokes services by calling RPC method.
Simply calls services via URL path.

What do I choose, SOAP or REST?
It depends!!

Both protocols have their advantages and disadvantages, but you should choose which protocol you are using based on the requirements of the problem. Instructing you on how to accomplish that is beyond the scope of this question and answer.
And in  .NET world, you can find more details to choose  :

And REST is more popular from ASP.NET WEB API.

And the use of SOAP is here from WebServices :
https://msdn.microsoft.com/en-us/library/ms972326.aspx
http://www.codeproject.com/Articles/1231/ASP-NET-Web-Service
https://msdn.microsoft.com/en-us/library/t745kdsh.aspx

We will add a sample next post using REST ASP.NET WEB API 2.0




lundi 19 septembre 2016

Updates in .NET core 1.0.1 : updating your machine or your application to use .NET core


1.     Updating your Machine to use .NET Core 1.0.1

- Install .NET Core 1.0.1 (https://www.microsoft.com/net/core#windows)

-  If you have already the last version 1.0.0, the installation of 1.0.1 version does not delete or otherwise update your current .NET Core.

2.     Updating your Application to use .NET Core 1.0.1
 You can do the update your .NET Core metapackage reference toMicrosoft.NETCore.App 1.0.1. (https://www.nuget.org/packages/Microsoft.NETCore.App/1.0.1)
An app configured this way will no longer run on .NET Core 1.0.0, even if it’s the only .NET Core version on a machine.
So, you just update to ASP.NET Core 1.0.1 and Entity Framework 1.0.1, by referencing a newer NuGet package.
So, we can see that in project.json file: