{"id":2753,"date":"2020-09-17T19:38:30","date_gmt":"2020-09-17T14:08:30","guid":{"rendered":"https:\/\/lng-consultancy.com\/staging\/5474\/?p=2753"},"modified":"2022-08-02T12:49:21","modified_gmt":"2022-08-02T12:49:21","slug":"dependency-injection-in-net-core","status":"publish","type":"post","link":"https:\/\/lng-consultancy.com\/staging\/5474\/dependency-injection-in-net-core\/","title":{"rendered":"Dependency Injection in .Net Core"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What is Dependency?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A\u00a0<em><strong>dependency<\/strong><\/em>\u00a0is an object that another object depends upon.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For example;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">public class EmployeeController : ControllerBase<br>{<br> IEmployee _employee = new EmployeeImplementor();<br> \/\/business logic<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u00a0In the above example<\/strong>, the class EmployeeController directly depends upon class EmployeeImplementor, so EmployeeImplementor is the dependency of class EmployeeController.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What Is Dependency Injection<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dependency Injection is a programming technique that makes a class loosely coupled by making it independent of its dependencies.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Injection dependency simply means that the dependency is pushed into the class from outside.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As per <strong>Dependency Inversion Principle<\/strong> a class should not depend upon concretion but rather abstraction. It means that dependencies should not be instantiated using the \u201cnew\u201c operator in a class, instead inject them from outside the class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>We can improve the above code<\/strong> by using dependency injection as follows:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">public class EmployeeController : ControllerBase<br>{\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<br>       private readonly IEmployee _employee;<br>       public EmployeeController(IEmployee employee)<br>      {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0_employee = employee;<br>\u00a0\u00a0\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ business logic<br>\u00a0 }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>In the above class<\/strong>, we have replaced the concrete dependency (EmployeeImplementor) with the abstract one (IEmployee) and it will be injected through the constructor form outside the class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why do we need Dependency Injection?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are many advantages:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Flexible Code<\/strong>: If we have multiple implementations for a service, we can switch one implementation with another without changing the business logic.<\/li><li><strong>Easy to test:<\/strong> Because we rely on interfaces over implementations -hence, we can more easily test our code.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Built in Dependency Injection in .Net Core<\/strong><strong><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">.NET Core provides a built-in Dependency Injection container,\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.iserviceprovider\">IServiceProvider<\/a>, Which is being used by a lot of internal services like:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Hosting Environment<\/li><li>Configuration<\/li><li>Routing<\/li><li>MVC<\/li><li>Logging<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The container is sometimes referred to as <strong>IoC,\u00a0Inversion of\u00a0Control\u00a0Container<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The overall idea is to\u00a0<em>Register<\/em>\u00a0at the application startup and then\u00a0<em>Resolve<\/em>\u00a0at runtime when needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Let\u2019s see an example<\/strong> where we will use .Net Core built in container for dependency injection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For this,<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Create an ASP.Net Core web application of API type and name it as \u201cCoreDependencyInjection\u201d.<\/li><li>Now, Create new folder and name it as Model.<\/li><li>Add the following files in the model folder:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">public class Employee<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public\u00a0 int Id { get; set; }<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public string Name { get; set; }<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public string Address { get; set; }<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">public interface IEmployee<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 List<Employee> GetAllEmployees();<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">public class EmployeeImplementor :IEmployee<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public List<Employee> GetAllEmployees()<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 List<Employee> employees = new List<Employee><br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 new Employee{Id=1, Name=\u201dNitin\u201d, Address=\u201dabc\u201d},<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 new Employee{Id=2,Name=\u201dAmit\u201d, Address=\u201dxyz\u201d}<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return employees;<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Now, we have added the domain class Employee.cs, an interface IEmployee.cs and its implementation EmployeeImplementor<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Now, under controller folder, add a new controller EmployeeController and add the following code in it:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">namespace CoreDependencyInjection.Controllers<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">{<br>\u00a0 [ApiController]<br>\u00a0 [Route(\u201c[controller]\u201d)]<br>\u00a0 public class EmployeeController : ControllerBase<br>\u00a0 {<br>\u00a0 \/\/ IEmployee _employee = new EmployeeImplementor();\/\/ Concrete Dependency<br>\u00a0\u00a0\u00a0 <br>    private readonly IEmployee _employee;<br>\u00a0\u00a0\u00a0 public EmployeeController(IEmployee employee)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0 _employee = employee;<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [HttpGet]<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public List<Employee> Get()<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return _employee.GetAllEmployees();<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0 }<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see that the Employee controller does not depend upon any concrete class, rather it\u2019s accepting the dependency through an interface using constructor injection.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Now, we will inject the dependency EmployeeImplementor() from our startup class with the following code:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public void ConfigureServices(IServiceCollection services)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 services.AddControllers();<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 services.AddSingleton<IEmployee, EmployeeImplementor>();<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The above code i.e.\u00a0 services.AddSingleton<IEmployee, EmployeeImplementor>() is Registering the type IEmployee with the type EmployeeImplementor. At run time, the type will be resolved and the dependency will be injected to the EmployeeController\u2019s constructor.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Now we can call the GetAllEmployees() of EmployeeImplementor class.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The benefit of this approach is that if in near future we found a new Implementation of IEmployee, we won\u2019t need to make any change in EmployeeController class. We will just need to update the registration of the type. \u00a0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Register Services in Container and Service Lifetime<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are different extension methods in the container to register services depending upon their Lifetime:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1) Singleton: <strong>Singleton<\/strong>\u00a0means only a single instance will ever be created. That instance is shared between all components that require it. The same instance is thus used always.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2) Transient: <strong>Transient<\/strong>\u00a0components are created every time they are requested and are never shared. This means, for example, that a service injected in the constructor of a class will last as long as that class instance exists.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3) Scoped: <strong>Scoped<\/strong>\u00a0means an instance is created once per\u00a0<em>scope<\/em>. A scope is created on every request to the application, thus any components registered as Scoped will be created once per request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Using Third party Ioc Containers<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apart from using the built-in container, .Net Core allows to use the third party containers, which provides more flexibility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will be using \u201cAutofac\u201d which is third party IoC Container, in our existing application. The main concept behind inversion of control is to let the caller decide how the dependencies are created, instead of the class deciding it. Therefore, the class never creates an instance, rather expects it to be passed by the caller.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>So, to begin with, add a reference to the nuget package Autofac.Extensions.DependencyInjection in your project.<\/li><li>After this, update the ConfigureServices() in the startup.cs with the following code:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">public IServiceProvider ConfigureServices(IServiceCollection services)<br>{<br>services.AddControllers();<br>\/\/Create the container builder.<br>var builder = new ContainerBuilder();<br>builder.Populate(services);<br>\/\/Register dependencies<br>builder.RegisterType<EmployeeImplementor>().As<IEmployee>();<br>var container = builder.Build();<br>\/\/return the IServiceProvider implementation<br>return new AutofacServiceProvider(container);<br>}<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You also need to update Program.cs file with the following code:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">public class Program<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static void Main(string[] args)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BuildWebHost(args).Run();<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static IWebHost BuildWebHost(string[] args) =><br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 WebHost.CreateDefaultBuilder(args)<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 .UseStartup<Startup>()<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 .Build();<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Using Middleware in .NET Core<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In .NET Core,\u00a0Middlewares\u00a0are the components that make up the HTTP pipeline that handles requests and responses for the application. Each piece of middleware called has the option to do some processing on the request before calling the next piece of middleware in line. After execution returns from the call to the next middleware, there is an opportunity to do processing on the response.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Let\u2019s take an example<\/strong> to log the Request and Response in the application using a middleware. For logging, we will be using \u201cSerilog\u201d. We need to install the following Nuget packages:<\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li>Serilog<strong><\/strong><\/li><li>Serilog.Sinks.File<strong><\/strong><\/li><\/ol>\n\n\n\n<ul class=\"wp-block-list\"><li>After this, we need to add a new class RequestResponseLoggingMiddleware:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">public class RequestResponseLoggingMiddleware<br>{<br>\u00a0\u00a0\u00a0 private readonly RequestDelegate _next;<br>\u00a0\u00a0\u00a0 private readonly Serilog.ILogger _logger;<br>\u00a0\u00a0\u00a0 public RequestResponseLoggingMiddleware(RequestDelegate next, Serilog.ILogger logger)<br>\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _next = next;<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _logger = logger;<br>\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0\u00a0 public async Task Invoke(HttpContext context)<br>\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/First, get the incoming request<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var request = await FormatRequest(context.Request);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _logger.Information(\u201crequest: \u201c+request);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Copy a pointer to the original response body stream<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var originalBodyStream = context.Response.Body;<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Create a new memory stream\u2026<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 using (var responseBody = new MemoryStream())<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u2026and use that for the temporary response body<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 context.Response.Body = responseBody;<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Continue down the Middleware pipeline, eventually returning to this class<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 await _next(context);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\/\/Format the response from the server<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var response = await FormatResponse(context.Response);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _logger.Information(\u201cresponse: \u201c+response);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Copy the contents of the new memory stream (which contains the response) to the original stream, which is then returned to the client.<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 await responseBody.CopyToAsync(originalBodyStream);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0\u00a0 private async Task<string> FormatRequest(HttpRequest request)<br>\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var body = request.Body;<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var buffer = new byte[Convert.ToInt32(request.ContentLength)];<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 await request.Body.ReadAsync(buffer, 0, buffer.Length);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var bodyAsText = Encoding.UTF8.GetString(buffer);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 request.Body = body;<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return $\u201d{request.Scheme} {request.Host}{request.Path} {request.QueryString} {bodyAsText}\u201d;<br>\u00a0\u00a0\u00a0 }<br>\u00a0\u00a0\u00a0 private async Task<string> FormatResponse(HttpResponse response)<br>\u00a0\u00a0\u00a0 {<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 response.Body.Seek(0, SeekOrigin.Begin);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 string text = await new StreamReader(response.Body).ReadToEndAsync();<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 response.Body.Seek(0, SeekOrigin.Begin);<br>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return $\u201d{response.StatusCode}: {text}\u201d;<br>\u00a0\u00a0\u00a0 }<br>}<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>To enable logging using serilog, We need to update our ConfigureServices() under Startup.cs with the following code:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">public IServiceProvider ConfigureServices(IServiceCollection services)<br>{<br>services.AddControllers();<br>services.AddSingleton((ILogger)new LoggerConfiguration()<br>.MinimumLevel.Information()<br>.WriteTo.File(\u201cLog.txt\u201d)<br>.CreateLogger());<br>var builder = new ContainerBuilder();<br>builder.Populate(services);<br>builder.RegisterType<EmployeeImplementor>().As<IEmployee>();<br>var container = builder.Build();<br>return new AutofacServiceProvider(container);<br>}<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>At last, we need to add the following code:<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">app.UseMiddleware<RequestResponseLoggingMiddleware>();<br><br>in our Configure() method in startup.cs<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>When you run the application<\/strong>, you will see a Log file in you project\u2019s route folder where you can see the Log for request and response.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>It will be something like below:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/lgconsultancy.wpcomstaging.com\/wp-content\/uploads\/2020\/09\/image.png?resize=796%2C51&ssl=1\" alt=\"\" class=\"wp-image-2756\" width=\"796\" height=\"51\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>At Last, we can say that Dependency Injection can make an application even more flexible and Easily testable.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u2014 <strong>Nitin Sagar<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 What is Dependency? A\u00a0dependency\u00a0is an object that another object depends upon. For example; public class EmployeeController : ControllerBase{ IEmployee _employee = new EmployeeImplementor(); \/\/business logic} \u00a0In the above example, the class EmployeeController directly depends upon class EmployeeImplementor, so EmployeeImplementor is the dependency of class EmployeeController. What Is Dependency Injection Dependency Injection is a programming [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":7301,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"nf_dc_page":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[32],"tags":[55],"class_list":["post-2753","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development","tag-net-core"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Dependency Injection in .Net Core - L&amp;G Consultancy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dependency Injection in .Net Core - L&amp;G Consultancy\" \/>\n<meta property=\"og:description\" content=\"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 What is Dependency? A\u00a0dependency\u00a0is an object that another object depends upon. For example; public class EmployeeController : ControllerBase{ IEmployee _employee = new EmployeeImplementor(); \/\/business logic} \u00a0In the above example, the class EmployeeController directly depends upon class EmployeeImplementor, so EmployeeImplementor is the dependency of class EmployeeController. What Is Dependency Injection Dependency Injection is a programming [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/\" \/>\n<meta property=\"og:site_name\" content=\"L&amp;G Consultancy\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-17T14:08:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-02T12:49:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/landg-consultancy.com\/wp-content\/uploads\/2020\/09\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sakshi Sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sakshi Sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/\"},\"author\":{\"name\":\"Sakshi Sharma\",\"@id\":\"http:\\\/\\\/sh024.global.temp.domains\\\/~landgcon\\\/#\\\/schema\\\/person\\\/6bdd977118deb1267d93485b4c3d78e6\"},\"headline\":\"Dependency Injection in .Net Core\",\"datePublished\":\"2020-09-17T14:08:30+00:00\",\"dateModified\":\"2022-08-02T12:49:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/\"},\"wordCount\":2741,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/lng-consultancy.com\\\/staging\\\/5474\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1\",\"keywords\":[\".Net Core\"],\"articleSection\":[\"Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/\",\"url\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/\",\"name\":\"Dependency Injection in .Net Core - L&amp;G Consultancy\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/sh024.global.temp.domains\\\/~landgcon\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/lng-consultancy.com\\\/staging\\\/5474\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1\",\"datePublished\":\"2020-09-17T14:08:30+00:00\",\"dateModified\":\"2022-08-02T12:49:21+00:00\",\"author\":{\"@id\":\"http:\\\/\\\/sh024.global.temp.domains\\\/~landgcon\\\/#\\\/schema\\\/person\\\/6bdd977118deb1267d93485b4c3d78e6\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/lng-consultancy.com\\\/staging\\\/5474\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/lng-consultancy.com\\\/staging\\\/5474\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1\",\"width\":1200,\"height\":628},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/landg-consultancy.com\\\/dependency-injection-in-net-core\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/lng-consultancy.com\\\/staging\\\/5474\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dependency Injection in .Net Core\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/sh024.global.temp.domains\\\/~landgcon\\\/#website\",\"url\":\"http:\\\/\\\/sh024.global.temp.domains\\\/~landgcon\\\/\",\"name\":\"L&amp;G Consultancy\",\"description\":\"Your Technology Partner\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/sh024.global.temp.domains\\\/~landgcon\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/sh024.global.temp.domains\\\/~landgcon\\\/#\\\/schema\\\/person\\\/6bdd977118deb1267d93485b4c3d78e6\",\"name\":\"Sakshi Sharma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/643e7ef13568a97c9460ff8a2e6e6a87799759bfeb9cf82cc3ad15d7865d8509?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/643e7ef13568a97c9460ff8a2e6e6a87799759bfeb9cf82cc3ad15d7865d8509?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/643e7ef13568a97c9460ff8a2e6e6a87799759bfeb9cf82cc3ad15d7865d8509?s=96&d=mm&r=g\",\"caption\":\"Sakshi Sharma\"},\"url\":\"https:\\\/\\\/lng-consultancy.com\\\/staging\\\/5474\\\/author\\\/sakshisharma2012\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dependency Injection in .Net Core - L&amp;G Consultancy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/","og_locale":"en_US","og_type":"article","og_title":"Dependency Injection in .Net Core - L&amp;G Consultancy","og_description":"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 What is Dependency? A\u00a0dependency\u00a0is an object that another object depends upon. For example; public class EmployeeController : ControllerBase{ IEmployee _employee = new EmployeeImplementor(); \/\/business logic} \u00a0In the above example, the class EmployeeController directly depends upon class EmployeeImplementor, so EmployeeImplementor is the dependency of class EmployeeController. What Is Dependency Injection Dependency Injection is a programming [&hellip;]","og_url":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/","og_site_name":"L&amp;G Consultancy","article_published_time":"2020-09-17T14:08:30+00:00","article_modified_time":"2022-08-02T12:49:21+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/i0.wp.com\/landg-consultancy.com\/wp-content\/uploads\/2020\/09\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1","type":"image\/jpeg"}],"author":"Sakshi Sharma","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Sakshi Sharma","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/#article","isPartOf":{"@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/"},"author":{"name":"Sakshi Sharma","@id":"http:\/\/sh024.global.temp.domains\/~landgcon\/#\/schema\/person\/6bdd977118deb1267d93485b4c3d78e6"},"headline":"Dependency Injection in .Net Core","datePublished":"2020-09-17T14:08:30+00:00","dateModified":"2022-08-02T12:49:21+00:00","mainEntityOfPage":{"@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/"},"wordCount":2741,"commentCount":0,"image":{"@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/lng-consultancy.com\/staging\/5474\/wp-content\/uploads\/2020\/09\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1","keywords":[".Net Core"],"articleSection":["Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/","url":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/","name":"Dependency Injection in .Net Core - L&amp;G Consultancy","isPartOf":{"@id":"http:\/\/sh024.global.temp.domains\/~landgcon\/#website"},"primaryImageOfPage":{"@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/#primaryimage"},"image":{"@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/lng-consultancy.com\/staging\/5474\/wp-content\/uploads\/2020\/09\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1","datePublished":"2020-09-17T14:08:30+00:00","dateModified":"2022-08-02T12:49:21+00:00","author":{"@id":"http:\/\/sh024.global.temp.domains\/~landgcon\/#\/schema\/person\/6bdd977118deb1267d93485b4c3d78e6"},"breadcrumb":{"@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/#primaryimage","url":"https:\/\/i0.wp.com\/lng-consultancy.com\/staging\/5474\/wp-content\/uploads\/2020\/09\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1","contentUrl":"https:\/\/i0.wp.com\/lng-consultancy.com\/staging\/5474\/wp-content\/uploads\/2020\/09\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1","width":1200,"height":628},{"@type":"BreadcrumbList","@id":"https:\/\/landg-consultancy.com\/dependency-injection-in-net-core\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lng-consultancy.com\/staging\/5474\/"},{"@type":"ListItem","position":2,"name":"Dependency Injection in .Net Core"}]},{"@type":"WebSite","@id":"http:\/\/sh024.global.temp.domains\/~landgcon\/#website","url":"http:\/\/sh024.global.temp.domains\/~landgcon\/","name":"L&amp;G Consultancy","description":"Your Technology Partner","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/sh024.global.temp.domains\/~landgcon\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/sh024.global.temp.domains\/~landgcon\/#\/schema\/person\/6bdd977118deb1267d93485b4c3d78e6","name":"Sakshi Sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/643e7ef13568a97c9460ff8a2e6e6a87799759bfeb9cf82cc3ad15d7865d8509?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/643e7ef13568a97c9460ff8a2e6e6a87799759bfeb9cf82cc3ad15d7865d8509?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/643e7ef13568a97c9460ff8a2e6e6a87799759bfeb9cf82cc3ad15d7865d8509?s=96&d=mm&r=g","caption":"Sakshi Sharma"},"url":"https:\/\/lng-consultancy.com\/staging\/5474\/author\/sakshisharma2012\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/lng-consultancy.com\/staging\/5474\/wp-content\/uploads\/2020\/09\/Untitled-design-25.jpg?fit=1200%2C628&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/posts\/2753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/comments?post=2753"}],"version-history":[{"count":1,"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/posts\/2753\/revisions"}],"predecessor-version":[{"id":7302,"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/posts\/2753\/revisions\/7302"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/media\/7301"}],"wp:attachment":[{"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/media?parent=2753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/categories?post=2753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lng-consultancy.com\/staging\/5474\/wp-json\/wp\/v2\/tags?post=2753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}