I am developing a small game in a console application in .NET Core where the the start of the application is StartPlay
method of IGamePlay
interface. I have a class GamePlay
which implements this interface.
interface IGamePlay
{
void StartPlay(List<Person> ListOfPlayers, int deckSize);
void PlayFromShuffledCards(List<Person> ListOfPlayers, Stack<Card> shuffledCards);
void PlayFromDiscardCards(List<Person> ListOfPlayers);
}
In my main method I have the following code:
class Program
{
static void Main(string[] args)
{
var serviceProvider = new ServiceCollection()
.AddSingleton<IGamePlay,GamePlay>()
.AddSingleton<GamePlay>()
.BuildServiceProvider();
// Populate listof players
var gamePlay = serviceProvider.GetRequiredService<GamePlay>();
gamePlay.StartPlay(listOfPlayers,deckSize);
}
}
From my main method, I am directly calling StartPlay
of the gamePlay
class in the last line of the main method.
Is this a violation of DI principles? If yes, what is the best way to instantiate it from main?