Showing posts with label ConfigureServices. Show all posts
Showing posts with label ConfigureServices. Show all posts

Friday, April 10, 2020

Access config settings from appsetting.json in Controller using DI

In the previous post we saw the options to read config setting values in Startup, in this post we shall see on how to get the config setting values in the controller. We will inject the configuration object to the service and the same will be made available in the Controller using Dependency Injection.

Sunday, May 19, 2019

Dependency Injection in Asp.Net Core

Dependency Injection is a design pattern which helps eliminate dependency between various classes and modules in a larger application. Dependency Injection aims in creating dependent objects for a class outside the class and injecting them dynamically into the class, instead of instantiating the dependent classes inside the main class. By doing this Dependency Injection helps us develop Applications with better modularity and test-ability.

Asp.Net Core provides built in dependency injection support for applications, in previous versions of Asp.Net dependency injection was implemented using 3rd party libraries like StructureMap, Unity etc. ASP.NET Core provides a built-in service container, IServiceProvider. Services are registered in the app's Startup.ConfigureServices method.

In Asp.Net Core a dependent service is registered with the service container in the ConfigureServices method of the Startup class as follows.

Sunday, February 17, 2019

Hello World example in Asp.Net Core

In the previous posts we saw about what Asp.Net Core is, its features and its advantages. Let us get started with a simple Hello World example in Asp.Net Core. We will use Visual Studio for this example. We can use Visual Studio Code also for a simple example like this, but for complex example Visual Studio is a better tool, hence we will use Visual Studio for this example.

Before we begin the example make sure that .Net Core SDK is installed in the machine, also install Visual Studio. In this example we will use Visual Studio 2017. Let’s get started.

Sunday, February 10, 2019

Asp.Net Core Startup Configuration

Startup configuration for Asp.Net Core applications are defined in a startup file Startup.cs. This is similar to the global.aspx.cs file in the previous version of Asp.Net. Startup settings are important in Asp.Net Core since we need to define the execution pipeline during startup to handle all incoming requests.

There are 2 important methods in the Startup which define the execution sequence of Asp.Net core request execution.

Configure
ConfigureServices