Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning ASP.NET Core 2.0

You're reading from   Learning ASP.NET Core 2.0 Build modern web apps with ASP.NET Core 2.0, MVC, and EF Core 2

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788476638
Length 516 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Michel Bruchet Michel Bruchet
Author Profile Icon Michel Bruchet
Michel Bruchet
Jason De Oliveira Jason De Oliveira
Author Profile Icon Jason De Oliveira
Jason De Oliveira
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Title Page
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. What is ASP.NET Core 2.0? 2. Setting Up the Environment FREE CHAPTER 3. Creating a Continuous Integration Pipeline in VSTS 4. Basic Concepts of ASP.NET Core 2.0 - Part 1 5. Basic Concepts of ASP.NET Core 2.0 - Part 2 6. Creating MVC Applications 7. Creating Web API Applications 8. Accessing Data using Entity Framework Core 2 9. Securing ASP.NET Core 2.0 Applications 10. Hosting and Deploying ASP.NET Core 2.0 Applications 11. Managing and Supervising ASP.NET Core 2.0 Applications

Implementing advanced dependency injection concepts


In the previous chapter, you saw how dependency injection (DI) works and how to use the constructor injection method. But, if you need to inject many instances during runtime, this method can be quite cumbersome and can make it complicated to understand and maintain your code.

Therefore, you can use a more advanced technique of DI called method injection. This allows accessing instances directly from within your code.

In the following example, you are going to add a new service for handling game invitations and update the Tic-Tac-Toe application for being able to send emails for contacting other users to join a game, while using method injection:

  1. Add a new service called GameInvitationService in the Services folder for managing game invitations (adding, updating, removing, and more):
        public class GameInvitationService 
        { 
          private static ConcurrentBag<GameInvitationModel> 
           _gameInvitations; 
      ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime
Visually different images