Tuesday, September 4, 2018

Angular 6 - Routing How to do it


While developing Angular apps, I thought of compiling a list of things we need to know on each of the areas. Here I cover routing.

Basics
  • A routed Angular application has one singleton instance of the Router service
  • The router uses a first-match wins strategy
    • The wildcard route comes last because it matches every URL and should be selected only if no other routes are matched first
    • Use path: '**' to match invalid routes (any other route that is not defined) for 404 redirections
  • Use enableTracing: true for debugging purposes by passing as 2nd parameter to forRoot
  • The router uses browsers history.pushState for navigation
Router Link
  • Use RouterLinkActive directive helps identify active links. The router adds active css class to the a tag
  • After the end of each successful navigation life cycle, the router builds a tree of ActivatedRoute objects that make up the current state of the router. You can access the current RouterState from anywhere in the application using the Router service and the routerState property.

  • The router adds the <router-outlet> element to the DOM and subsequently inserts the navigated view element immediately after the <router-outlet>.
  • You can add redirectRoute for redirections (defined in router module)
  • Only call RouterModule.forRoot in the root AppRoutingModule (or the AppModule if that's where you register top level application routes). In any other module, you must call the RouterModule.forChild method to register additional routes. (article)
  • Always put app routing as last in main module
Authentication
  • Use CanActivate guard to manage navigation business rules
  • You can create component-less routes to manage authentication easily
  • You can create a service which extends CanActivate which coul contain the security logic
    • Use canActivate attribute with that service
  • You can use CanActivateChild guard to protect child routes. It runs before any child route is activated

Sunday, August 19, 2018

Domain Driven Design - What is it and why

What is DDD?

In very simple terms DDD is about making your software as a model of a real world system or a process. When practicing DDD you'll work with a domain expert to build a ubiquitous language (UL). UL is a conceptual description of the system. UL is written down in such a way that domain expert should be able to understand and verify the UL is correct.

UL will include words that is used in actual domain. UL forms the basis of the OO design. DDD will have  following object categories
  • Value objects
  • Entities
  • Aggregate roots 

Recommended patterns for DDD
  • Repository 
  • Factory
  • Service

When not to use DDD (airbrake)

DDD is not suitable for projects where requirements and domain expertise is less. DDD sometimes goes in as an iteration which may not be suited for some projects. It may not be suited for projects which involves high technical complexity as opposed to domain complexity as well. 





Notes

https://stackoverflow.com/questions/1222392/can-someone-explain-domain-driven-design-ddd-in-plain-english-please/1222488#1222488

https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/ddd-oriented-microservice

https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/net-core-microservice-domain-model



Sunday, August 12, 2018

All you need to know about Angular

Angular Main Concepts

Directives

Directive is a function which gets executed whenever Angular compiler find one in the DOM. There are component, structural and attribute directives.

Modules

NgModules consolidate components, directives, and pipes into blocks of functionality.

Components and Life cycle hooks

Dynamic components, Component interaction, Attribute and Structural directives

Observable and Subject


Routing


Services


Forms

Template driven forms, Reactive forms, Form validation and Dynamic forms


Angular Advanced Topics


Server side rendering

Service worker and PWA

Security

Compiling


Wednesday, July 4, 2018

Integrating Repository Layer with Service Layer

Nowadays it is very common to use repository pattern to improve readability and maintainability of projects. But things gets complex when you have multiple repositories and services interacting with each other. 

When you have many of these it is important to find ways to generalize things so original requirement of readability and maintainability is achieved. 


Resources

Tuesday, July 3, 2018

Organizing Resources in Azure with Resource Manager

When working with large scale projects proper organization of resources is a necessary. Azure has resource groups for grouping resources as required.

Resource Manager in Azure

You can use resource manager to organize resources within a subscription. Use it to control access, audit and tagging resources. Actions you take in azure are handles through resource managers. 


Following is how azure structure can be seen from scope prospective 


Template deployment in Azure Resource Manager

In large scale deployments you can use azure templates for automate tasks. Templates are simply JSON files containing metadata about the resources.


Integrating Azure Key Vault in Azure Resource Manager template deployment

You can pre-store the password in an Azure key vault and then customize the template to retrieve the password from the key vault during the deployment. Check this tutorial.

Resource Access Management in Azure


Friday, June 15, 2018

Internet of Things

IoT, Internet of Things is a system of interrelated computing devices which communicates over a network and can be remotely monitored.

Image Credits: Embitel India 
Some of the key goals of IoT is to,

  • Improving business processes
  • Improving customer experience
  • Reducing costs
  • Increasing competitiveness
Some of the challenges in IoT are,
  • Data/network security
  • Integrating with business processes
  • Expected ongoing costs
  • Upfront capital investment requirements
  • Integrating with existing ICT infrastructure

Edge Computing

Edge computing is the practice of processing data near the edge of your network, where the data is being generated, instead of in a centralised data-processing warehouse. (Microsoft Azure enables a new wave of edge computing. Here’s how.)



Tuesday, June 12, 2018

Angular Components



In general a component controls a part of the screen or a view. Angular creates, updates, and destroys components as the user moves through the application. Your app can take actions on component using life cycle hooks suck as ngOnInit().

@Component decorator identifies a class as a component. You can keep metadata here. A component usually accommodated by a view.

Component Interaction

  • Using @Input parameters
  • Event listeners with EventEmitter
  • Parents call a @ViewChild()

Friday, March 30, 2018

Artificial Intelligence and Beyond

Artificial Intelligence is not a buzzword nowadays. Instead what we hear mostly today is concepts like machine learning, deep learning, natural language processing (NLP) etc. But one should understand that. This all comes under Artificial Intelligence.

Image Credits: Quora

Artificial Intelligence 

Is the intelligence performed by the machines instead of by humans or other animals by natural intelligence. AI would perceive information it gets, process it gives a better meaning than it previously had. 

Machine Learning

Is how a machine learns to perform a task and gain more information (learn) by looking at the patterns it gets. 

Image Credits: Medium
Deep Learning: is a concept where machine learning creates artificial neural network that can take intelligent decisions on its own. 



Natural Language Processing (NLP)

Is how a program process and analyzes large amount of data.

IBM Watson is a question-answering system capable of answering questions in natural language. 

Sentence segmentation is a technique used to identify similar sentences. 


Tuesday, March 13, 2018

Serverless Computing - Azure Functions

In Serverless computing cloud provider provides backend as a service. The architecture is inherently scalable, can be deployed quickly. But comes with a cost such as testing and debugging. 

Azure Functions is the implementation in Azure. Azure functions can be integrated with Cosmos DB, Service bus and Storage.

Serverless APIs with Azure Function Proxies

Azure functions can be used to host an API. Not very often you host APIs in Functions. But this s a good way for scalability, costs or ease of implementation.

Cloud Messaging in Azure

You can enhance the behavior in Azure by using following

Event Grid

Fully managed event routing services by connecting serverless logic to events.



Service Bus

Messaging infrastructure in Azure.


Logic Apps

Helps you to provide workflows allowing developers to integrate data with their apps.

Analytics

Azure Stream Analytics allows you to query data in SQL like language

Serverless computing in AWS




Resources

https://azure.microsoft.com/en-us/services/functions/

Wednesday, November 15, 2017

Angular Modules

Angular libraries are NgModules, such as FormsModule, HttpClientModule, and RouterModule. Many third-party libraries are available as NgModules such as Material Design, Ionic, and AngularFire2.

NgModules consolidate components, directives, and pipes into cohesive blocks of functionality, each focused on a feature area, application business domain, workflow, or common collection of utilities.

  • declarations: The components, directives, and pipes that belong to this NgModule.
  • exports: The subset of declarations that should be visible and usable in the component templates of other NgModules.
  • imports: Other modules whose exported classes are needed by component templates declared in this NgModule.
  • providers: Creators of services that this NgModule contributes to the global collection of services; they become accessible in all parts of the app. (You can also specify providers at the component level, which is often preferred.)
  • Entry Components: An entry component is any component that Angular loads imperatively, (which means you’re not referencing it in the template), by type. You specify an entry component by bootstrapping it in an NgModule, or including it in a routing definition.


Tuesday, October 17, 2017

Hoisting in JavaScript

Due to it's somewhat awkward behavior, concepts in JavaScript is little tricky to understand. Hoisting is one of them. Hoisting can be divided in to two. Variable hoisting and function hoisting. We'll first look at variable hoisting.


Variable hoisting


If you execute below line you'll get a ReferenceError.


This is because definition for value1 is not exist. Now consider below.


Even though value1 is defined after line1, still it'll say value1 is undefined. But won't show the value. This is because JavaScript interpreter goes through the file and "hoist" the variable definitions on top of the function. But value assignment happens later.

you must have expected var1 to print 1 since it was defined in the outer scope. But due to function hoisting and functional level scoping it will print undefined. But since var2 doesn't exist in current scope, it will get value 2 and print it. This is the reason it's recommended to declare all variables on top of a function.


Function hoisting


Unlike variables, functions doesn't just hold the function name, it holds the actual function definition.


something to remember is that function hoisting happens only for function defintions. Not function expressions.

Here the variable func2 will be defined but not the function definition. (TypeError). JavaScript only has function level scoping.

function declarations and variable declarations are always moved('hoisted') invisibly to the top of their containing scope by the interpreter. Function parameters and language defined names.


Resources

http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html

Monday, July 3, 2017

Introduction to Azure Search

Azure search is simply a cloud service which gives developers an API for rich search experience. It executes queries over a user-defined index.

Azue search supports,

  • Search data from multiple content types and platforms
  • AI powered indexing to extract text from image files or key phrases from raw text
  • Create search experience with filters, synonyms, auto-complete and text analysis for "did you mean" auto correct search terms
  • Geo-search for find near me.
Functionality is exposed over a REST API or .NET SDK.  

Azure search comes with following features

  • Full text search and text analysis
  • Cognitive search (in preview)
  • Data integration
  • Linguistic analysis
  • Geo-search
  • User experience features
  • Relevance
  • Monitoring and reporting
  • Tools and prototyping and inspection
  • Infrastructure

Steps to use
  • Provision service
  • Create index
  • Load Data
  • Search

Indexer
Indexer is a crawler that extracts searchable data and metadata from a external Azure data source and populate index based on field-to-field mapping between indexer and data source.

Connecting Azure Search with Azure SQL Database
https://docs.microsoft.com/en-us/azure/search/search-howto-connecting-azure-sql-database-to-azure-search-using-indexers


Tuesday, February 21, 2017

Authentication and Authorization in ASP.NET Core

Common vulnerabilities in software

  • Cross-site scripting attacks
  • SQL Injection
  • Cross-Site request forgery
  • Open redirect attacks

Authenticiation

ASP.NET Core Identity is a membership system that adds login functionality to ASP.NET Core apps. External login providers are also supported. (Read the article) Identity is enabled by calling UseAuthentication() which adds authentication middleware to the request pipeline. (In ASP.NET Core 1.x this was UseIdentity() - See Migration Guide)

When signing out, SignOutAsync clears the user's claims stored in a cookie. You can also add custom user data to Identity. 


Tuesday, February 7, 2017

Software Architecture Design - Considerations

Image Credits  : Colour Box


Architecture of anything defines how well the thing is designed and how long it's going to last. Be it a a building, a car or anything the same rule applies. It is the same when it comes to a software architecture as well.

If the architecture of a software is designed well, it should be able to accommodate any or many of the requirements be it functional or non-functional, the stakeholders requests. Therefore when designing a good architecture, one should be very careful when laying the foundation.

Keep in mind the following non-functional requirements when you're designing the initial architecture of your application.

Scalability


High Scalability has many practical case studies. It is important to keep in mind how much scalable your application is going to be in coming milestones. Size of codebase also matters

  • Scale up (Increase power of hardware)
  • Scale out  (Increase no. of hardware)
Scalability of Django. This video demonstrate how Instagram scales.

Instagram has a caching(memcache) mechanism between database and the client. Whenever user is served it keeps it in the cache as well as update primary and secondary storage.



Read What is scalability for more information


Performance

This is a key fact when the application grows larger. This might not matter initially but it should be kept in mind as the application grows. Some considerations for performance are,

  • Perceived performance (Fluent Conf 2017 - Video)  : Measure of How Quick a User Thinks Your Site Is. 
    • If you look at some websites it first loads the content placeholders which is mainly html and then only loads the actual data which takes time
    • Applicable for mobile apps as well. First loads the placeholder before loading data from server
  • Bundle & minification : Reduces the size of files that needs to be downloaded
  • Caching & content delivery networks
  • Optimizing image usage

Web Performance: Leveraging the Metrics that Most Affect User Experience (Google I/O '17)

Re-usability

Make sure to design common things in such a way that they can be reusable.

Supportability

What devices is your application going to support in future? Can the architecture be designed in a way that it supports future requirements of new devices?

See - Azure Design Guideline

There are lot of other things which should be considered when designing an architecture. But most importantly,

"make sure to think through cost and the benefit for every decision you make."

Wednesday, February 1, 2017

Tuesday, January 31, 2017

Getting Started with Azure CDN

For a better user experience and a faster delivery of content from server to client, both caching and CDN (content delivery network) comes hand in hand. When considering performance it is important to use both of  these techniques for better user experience (See Caching vs CDN - Stackoverflow).

CDN can be used to cache static web content to provide content faster to end users. It caches content in physical nodes across the globe.

Watch this video to understand how to link a storage account with Azure CDN.



Resources
https://azure.microsoft.com/en-us/blog/enabling-cdn-for-azure-websites/
https://docs.microsoft.com/en-us/azure/cdn/cdn-create-new-endpoint

Wednesday, January 25, 2017

Catch these things in EF Core

            var b = _context.Tasks.Include(j => j.TaskItems).Include(j => j.Creator);

TaskItems is an ICollection in Task object, hence it'll execute separately in SQL Server. Since Creator is a 1 to 1 mapping, It'll do a inner join with Task.


            var a = _context.Tasks.Include(j => j.TaskItems).ThenInclude(j => j.Status);

First tasks will be queried. Then in another query, TaskItems will be left joined with Workflow status. To map with Tasks, Where query will be appended with Exists, which will map Tasks and TaskItems


Thursday, January 12, 2017

Microservices what is it really

Image Credit : Contentful

Microservices is a architectural pattern where a structure of an application is decomposed as collection of loosely coupled services. These services are responsible for handling separate business capabilities.

Microservices helps software teams to continuously deliver large scale complex application in pieces. (Should you use microservices)

We all can search and find theories of microservices, but practical use cases and practical issues are what most of us will be interested in espeically when such resources are rare. So I thought of organizing this page to list some concerns involved.

Image Credits : Bhagwati Malav (via. Medium)

Problems with Monolithic Architecture

Traditionally monolithic architecture is used for many software's but it generates bigger problems with time.

  • Involves a single code base which increases code complexity, learning curve, maintainability, dependencies
  • Overloads IDE since there's only single code base
  • Difficult continuous integration since all application is a single one
  • Scaling is linear. Since there is no modularity all modules comes as a single package. Cannot scale different modules separately based on the requirement (Even if module A gets used 99% and B 1% both will be handled via. same infrastructure) 
For smaller teams most of the time monolithic will be the way to go. Consider microservices if you  have previous experience but not because you want to try it. If your application tends to get bigger , much complex or if you encounter a non-functional business requirement such as one part of the application need higher performance consider using microservices. This is because separate services can scale independently. Note that what can be done in monolithic can be done in microservices as well.

Patterns in Microservices

There are patterns which can be used with Microservices.

API Gateway (source)

There could be requirements from front-end to have an API which would access multiple microservices to retrieve data. Solution here is to create a separate API Gateway which would access required microservices and give what you need. 

API Composer is when you need to query multiple services where services uses Database per service pattern. API Gateway often does API composition as well. 


Microservices in Azure - Service Fabric

https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-overview-microservices
https://azure.microsoft.com/en-us/blog/microservices-an-application-revolution-powered-by-the-cloud/
https://docs.microsoft.com/en-us/azure/service-fabric/

Case studies
https://blogs.msdn.microsoft.com/azureservicefabric/tag/case-study/

Authentication in Microservices

https://stackoverflow.com/questions/29644916/microservice-authentication-strategy

Microservices - Case Studies






Sunday, January 1, 2017

ASP.NET Core Request Pipeline

With ASP.NET to ASP.NET Core lot of things has changed. ASP.NET had a request processing pipeline with lots of events such as BeginRequest, EndRequest etc. With Core the architecture was changed.

This is how ASP.NET Core application is initialized



ASP.NET Core now has the concept of Middlewares. You can have many middlewares as you need and each of them will execute one after the other.

Fundamentals of Middleware

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-2.2

You can also write your own custom middleware

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/write?view=aspnetcore-2.2
Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook