Book Image

ASP.NET Core Essentials

By : Shahed Chowdhuri
Book Image

ASP.NET Core Essentials

By: Shahed Chowdhuri

Overview of this book

<p>ASP.NET Core is the latest collection of Microsoft’s web application development technologies. When you’re trying to reach a broad spectrum of users with a robust web application, ASP.NET Core is there to help you build that application. With the ability to cater to users on desktop, tablet, or smartphone platforms, you can put together a solution that works well anywhere.</p> <p>This book is what you need to get started developing ASP.NET Core applications was quickly as possible; starting by introducing the software and how it can be used in today’s modern world of web applications and smartphone apps. Walking you through the benefits of a Web API to support both applications and mobile apps to give you a solid understanding of the tech to build upon as you see what ASP.NET Core can do for you.</p> <p>The book wraps up with practical guidelines for the use of database technologies, unit tests, security best practices, and cloud deployments for the real world.</p>
Table of Contents (15 chapters)
ASP.NET Core Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Implementing DI in ASP.NET Core


Before we proceed, you may be surprised to know that we already have DI in the sample project that we have been working with in earlier chapters. Take a look at the Startup.cs file in your web project folder. You should see the following code near the end of the ConfigureServices() method:

services.AddTransient<IEmailSender, AuthMessageSender>(); 
services.AddTransient<ISmsSender, AuthMessageSender>(); 

This code adds a couple of instances of the AuthMessageSender service class, which implements both the IEmailSender and ISmsSender interfaces. The code for this class and its interfaces can be found in the Services subfolder of your project, as shown in the following screenshot:

The call to AddTransient ensures that the object is properly created and destroyed, so that you don't have to worry about instantiation and disposal. There are multiple ways to indicate what kind of life cycle you want. Life cycle management is an integral part of using...