Posts

Showing posts from August, 2018

Microsoft Enterprise Library-Data Access Application Block for for .Net Core & .Net Standard

Ref: https://www.nuget.org/packages/EnterpriseLibrary.Data.NetCore/ The Enterprise Library Data Access Application Block simplifies the development of tasks that implement common data access functionality. Applications can use this application block in a variety of situations, such as reading data for display, passing data through application layers, and submitting changed data back to the database system. This library contains a class library that targets .Net Core 2.0 & .Net Standard 2.0 Install-Package EnterpriseLibrary.Data.NetCore -Version 6.0.1313

Asp .Net Core -Startup Class and the Service Configuration

Ref:  https://code-maze.com/aspnetcore-webapi-best-practices/ In the  Startup  class, there are two methods: the  ConfigureServices  method for registering the services and the  Configure  method for adding the middleware components to the application’s pipeline.  public static class ServiceExtensions     {         public static void ConfigureCors(this IServiceCollection services)         {             services.AddCors(options =>             {                 options.AddPolicy("CorsPolicy",                     builder => builder.AllowAnyOrigin()                     .AllowAnyMethod()                     .AllowAnyHeader()                     .AllowCredentials());             });         }         public static void ConfigureIISIntegration(this IServiceCollection services)         {             services.Configure<IISOptions>(options =>             {             });         }         public static void ConfigureMVC(this IServiceCollectio

Repository Pattern

Ref:  https://code-maze.com/net-core-web-development-part4/ https://docs.microsoft.com/en-us/aspnet/core/fundamentals/repository-pattern?view=aspnetcore-2.1 https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application https://stackify.com/dependency-injection-c-sharp/ https://docs.microsoft.com/en-us/aspnet/core/fundamentals/repository-pattern?view=aspnetcore-2.1 http://tutorials.jenkov.com/dependency-injection/dependency-injection-benefits.html Repository Pattern: With the Repository pattern, we create an abstraction layer between the data access and the business logic layer of an application. By using it, we are promoting a more loosely coupled approach to access our data from the database. Also, the code is cleaner and easier to maintain and reuse. Data access logic is in a separate class, or sets of classes called a repository, with the resp

Asp .Net Core

Image
Global exception handler: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-2.2 Asp.net core hosting Issue: https://blogs.msdn.microsoft.com/benjaminperkins/2018/06/07/asp-net-core-2-1-and-http-error-502-5-process-failure/ ASP.NET Core Refere https://www.tutorialsteacher.com/core/aspnet-core-introduction nces: ASP.NET Core is a free, open-source and cloud optimized web framework which can run on Windows, Linux, or Mac.  ASP.NET Core is a modular framework distributed as NuGet packages. This allows us to include packages that are required in our application. ASP.NET Core is designed to be deployed on cloud as well as on-premises. Developers can now build cloud-based web applications, IoT (Internet of Thing) and mobile backend applications using ASP.NET Core framework which can run on Windows, Linux, and Mac operating systems. Version Release Date ASP.NET Core 2.0 August 2017 ASP.NET Core 1.1 November 2016 ASP.NET Co

ASP.NET Core 2.0 Configuration with XML/Json File

Ref: https://joonasw.net/view/asp-net-core-1-configuration-deep-dive            var configurationBuilder = new ConfigurationBuilder();             configurationBuilder.SetBasePath(_env.ContentRootPath);             configurationBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);             configurationBuilder.AddXmlFile("appsetting.xml",false, true);             var configuration = configurationBuilder.Build();             var value = configuration["Logging:IncludeScopes"];             string adminEmail1 = configuration["SiteSettings:AdminEmail"]; xml file: <configuration>   <SiteSettings>     <AdminEmail>user@localhost</AdminEmail>     <UploadFolder>Uploads</UploadFolder>     <Logo>/images/logo.png</Logo>     <Timeout>20</Timeout>   </SiteSettings> </configuration> Json File {   "Logging&qu

Json/XML Request parameter schema validation

 public class ValidateAttribute : ActionFilterAttribute     {         public override void OnActionExecuting(ActionExecutingContext filterContext)         {             try             {                 if (filterContext.HttpContext.Request.Method == "POST")                 {                     string requestData = string.Empty;                     using (var reader = new StreamReader(filterContext.HttpContext.Request.Body))                     {                         filterContext.HttpContext.Request.Body.Seek(0, SeekOrigin.Begin);                         requestData = reader.ReadToEnd();                         if (string.IsNullOrEmpty(requestData))                             filterContext.Result = new BadRequestResult();                     }                     if (filterContext.HttpContext.Request.ContentType == "application/xml")                     {                         string errorMessages;                         var isValidXml