Thursday, July 26, 2018

Python TypeError must be str not int

While working on Modules using python using an IDE PyCharm i confronted an issue while printing int value using Print function of python.I’ve created a python module which i require to import prior to use.

Now question strikes in mind what actually Module is in Python.

I’ve craeted a fle named as Functions and having the below given code:

Tuesday, May 8, 2018

Shared my learning about .Net Core 2.0 with Angular with it's inbuilt template and many more in Noida .Mitigation of Challenges faced with earlier version of .NetSome glimpse of the day#dotnetcore2.0#Angular #mvpbuzz #asp.net

Monday, April 30, 2018

Missing Registration For Location Error while Publishing the API on Azure.

Introduction:

Missing Registration For Location Error Can come when we are trying to publish the web application on azure from Visual studio.

Solution:

I’ve tried various way to resolve this and various website advised to me to update visual studio or Upgrading Azure SDK will resolve your problem however this didn’t work. So I used alternative approach for publishing.

Steps:

Publish your web application using visual studio. It gives this error. but It creates App Service Plan and App Service in Azure.

Monday, March 26, 2018

Abstract Factory Pattern Using C# - Real World Example

While learning about design patterns, I came to understand the most frequently used term, Factory Pattern as well as Abstract factory pattern. I searched the internet and came across numerous learning points. After a lot of search and study, I endeavored to find an actual need for the abstract design pattern.

In this article, I will explore this pattern in an easy way so that everyone can have a better understanding of it. Down the level, I'm using a Car (Vehicle) example to demonstrate abstract factory pattern.

An important aspect of software design is the manner in which objects are created. Thus, it is not only important what an object does or what it models, but also in what manner it was created.

Reference: http://www.dofactory.com/DefinitionProvide an interface for creating families of related or dependent objects without specifying their concrete classes.

Definition

I'd keep the structure in such a way as depicted below.Participants

The classes and objects participating in this pattern are:

AbstractFactory (IVehicleFactory)

declares an interface for operations that create abstract products.

ConcreteFactory (MarutiFactory, TataFactory)

implements the operations to create concrete product objects.

AbstractProduct (ICarEngine, ICarLight)

declares an interface for a type of product object.

Product (DDis, LED, Revtron, Helogan)

defines a product object to be created by the corresponding concrete factory.

Thursday, January 4, 2018

Custom Service Dependency Injection In .Net Core 1.1

There are various ways to inject dependency in MVC. Dependency injection is a technique to pass the required Dependency so that the desired action can be performed.In this article we will go through with one of the key features of .Net Core, Custom Service dependency injection in .Net core 1.1, particularly at controller’s action level .Here are some important points which will help you to understand the facts easily in the following excerpts:

Dependency Injection

Dependency Injection (DI) is a pattern that shows how we can create loosely coupled classes. It means Class A is not directly dependent on class B and an object injects the dependency of another object. A dependency is an object that can be used as service, which is a part of this article.

Earlier in .Net there were some well-known dependency resolvers like Unity, Autofac and Ninject and so on.

.Net Core allows you to inject dependency out-of-the-box, there is no need to add the reference of the above mentioned dependency resolver. As soon as you create a solution you will be able to configure services easily, .Net Core manages this operation at its level that indeed helps a developer to get rid of this matter.

This article explains about how to configure custom service in .Net core and inject that service object in controller’s constructor as well as in action method. In the earlier versions of .Net it used to not inject the dependency at Action level. This is recently introduced with the release of .Net core. Action level injection of service makes an application lighter than controller level. Consider a scenario when you have a number of action methods defined in a single controller and you have injected the service at controller’s constructor. Though it’s being used at one action only, it looks like it’s not worth it.

PREREQUISITES

Visual Studio 2017 Enterprise/Professional

.Net Core 1.1

IMPLEMENTATION

In order to understand the dependency injection in .Net core 1.1, kindly refer to the given below image which states how the client application needs an object to access the implementation of given methods.

Now create a custom service class file as depicted below in screen shot:

There is a startup class file which exists in solution and has two methods ConfigureServices and configure. Refer to the below image to know more about startup class file location under solution structure.

This method executes its functionality at runtime. Both operations have a different set of objectives as shown below,

ConfigureServices

This method gets called by the runtime. Use this method to add services to the container. And it takes one IServiceCollection object as an input. Refer to the given below screenshot.

ConfigureThis method gets called by the runtime. Use this method to configure the HTTP request pipeline.

Register Your Custom Services

To register your custom application services in ConfigureService method kindly put an interface definition object type that will be requested from the container. The second type represents the concrete type (class) thaFit will be instantiated by the container.

services.AddSingleton<IFirstService, FirstService>();

If you notice in figure4, it has an IServiceCollection object which registers IFirstService object as singleton. Though there are two more ways to register your dependency in .Net core, those are AddScoped and AddTrsnsient as shown below,

services.AddScoped<ArticlesService>();

services.AddTransient<ArticlesService>();

Now create a product controller under controller’s folder and inject dependency in either of controller’s action, as shown below in screen shot,

Open Product Controller and inject IFirstService dependency in Details action method. Kindly refer to the below image for ref,

Wednesday, January 3, 2018

Recently, I created a Chabot for a purpose which I wanted to register within. After an implementation of Bot using MS Bot framework, it should be registered with https://dev.botframework.com/bots.

These are a few steps which may help you to register and ready to use.

Step 1 Go to https://dev.botframework.com/bots. You will have the following section there as given in the below screenshot.

Step 2 Click on "My Bots" and further, click on "Create a bot".

Step 3Click on "Create" button as shown in given image and the following window will appear.

Step 4Choose the first option from the given screen and click OK.

Step 5As soon as you create click ok, it generates AppId which might be essential at down the level during accessing the Bot which you have created.

Step 6Click on "Generate an app password" to continue.

Note Kindly save this password in Notepad for future purpose.

Step 7:After performing all the above steps, it is time to set configuration as given below.

It may prompt you to keep https instead of http,Step 8

Once you are done, click on register and it will prompt to as Bot created in the given screenshot.

Step 9As soon as you have created and registered your Bot, click on the recently registered Bot as depicted below in the screenshot.

It will take you to the next level which advises you to test your Bot. Step 10

Click on the Test button showing in right top corner. Click on that. It will prompt you another window and put "hi" in the chat window. As soon as you type something, it starts responding you which confirms that Bot has been register successfully.

Short circuiting and branching in .NET Core are key concepts to make an application sequential and provide more control over the response.

The term middleware is used in a .NET Core application either to delegate a request to the next component in the pipeline or short circuit it.

Middleware has some important aspects as shown below:

It delegates the request to the next component in the pipeline.

Business logic can be written before and after the component is invoked in the pipeline.

There are three extension methods Run, Map, and Use which can be configured as request delegates.

Each request delegated can be written as a single line as an anonymous method (aka in-line middleware) or separately as a middleware component.

These components are responsible for invoking the next delegate in the pipeline or to short circuit it.

.NET Core request pipeline comprises request delegates, which call one after another as the image shown below:

Reference: MSDN

Each delegate can also decide not to pass a request to the next delegate, which is known as short circuiting. An advantage of short circuiting is, it doesn’t pass the request to the following delegate if it doesn’t meet specific criteria. For example, if a request doesn’t have a specific parameter in its URL, then it can short circuit the pipeline and returns the response directly from there.

On the other hand, branching helps to map the request based on matches and executes the specific branch (can be a method).

Map and MapWhen extensions are provided by .NET Core by default for branching the pipeline.

Kindly refer to the image below for better understanding:

Let’s practically see all this.

PREREQUISITES

Visual Studio 2017 Enterprise/Professional

.Net Core 1.1

IMPLEMENTATION

To understand the short circuiting and branching in .NET Core 1.1, refer to the figure below for a solution structure:

Open a startup.cs file and search for configure method; it comes out-of-box with .NET Core applications.

CONFIGURE:

This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

Figure3.

SHORT-CIRCUITING:

To meetpurpose I’ve written code using Use extension method and set a limitation so that if a specific request contains a query string in its URL, then it should not go further in pipeline otherwise it should go till the Run method.

Facebook Like

Total Count

Vistor's

Live Traffic Feed

About Me

am Sachin Kalia .I work in .Net technologies and work in software company in Noida.I share my thoughts about .Net and associated technologies through C#Corner and DotnetPiper.I feel its a great platform to learn grooming technologies and also share my experiences to help community.I also maintain my own personal blog http://dotnetpiper.blogspot.in/ .Besides technologies i also like to play cricket,swimming and any activity which makes me happy.