Dependency Injection in .NET Core 2.0 by Marino Posadas

Dependency Injection in .NET Core 2.0 by Marino Posadas

Author:Marino Posadas
Language: eng
Format: epub
Tags: COM051200 - COMPUTERS / Programming Languages / Visual BASIC, COM051000 - COMPUTERS / Programming / General, COM051230 - COMPUTERS / Software Development And Engineering / General
Publisher: Packt
Published: 2017-11-08T11:16:06+00:00


If you understand cricket a little bit, you must know that a player uses a bat to bat. That means it depends on the bat object. The bat object, however, can be used by any batsman in the team, which leads to a StartPlay method in the Bat class. Obviously, the bat object needs to get associated with a player, which eventually commences the game.

Both of the objects depend on each other in order to start the game. They still exist as independent objects. Suppose, you don't call the Play and StartPlay method, nothing will change. The code will compile. That defines the association with each other for a common cause:

CricketPlayer cPlayer = new CricketPlayer("Hardik Pandya"); Bat bat = new Bat(); //cPlayer.Play(bat); //bat.StartPlay(cPlayer);

Console.WriteLine($"Name of the Player is: {

cPlayer.GetPlayerName() }");

Console.WriteLine($"Brand of Bat is: { bat.GetBrandName() }");

Here, I just commented out codes for play. That did not have any impact on the objects and they still exist. Then I used them to call other methods like GetPlayerName and GetBrandName.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.