Multiple solutions for bullet 6.

This commit is contained in:
emantzoros 2025-09-19 23:05:33 +03:00
parent b03a58fc92
commit 15df86fad7
14 changed files with 108 additions and 16 deletions

View File

@ -7,4 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>
</Project>

4
Bullet6/IFlow.cs Normal file
View File

@ -0,0 +1,4 @@
public interface IFlow
{
Task Start();
}

View File

@ -1,15 +1,25 @@
using Bullet6.Handlers;
using Bullet6.Interfaces;
using Bullet6.Models;
using Bullet6.Solution1;
using Bullet6.Solution2;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Bullet6
{
public class Program
{
static void Main(string[] args)
static async Task Main(string[] args)
{
IEntity[] entites = [new Employee() { Name = "Ilias" }, new Manager() { Name = "Maria" }];
foreach (var entity in entites) EntityHandler.PrintName(entity);
ServiceCollection services = new ServiceCollection();
services.AddSingleton<ISolution1Service, Solution1Service>();
services.AddSingleton<ISolution2Service, Solution2Service>();
var serviceProvider = services.BuildServiceProvider();
List<IFlow> flows = new List<IFlow>()
{
serviceProvider.GetRequiredService<ISolution1Service>(),
serviceProvider.GetRequiredService<ISolution2Service>()
};
foreach (var flow in flows) await flow.Start();
}
}
}

View File

@ -0,0 +1,7 @@
namespace Bullet6.Solution1
{
public interface ISolution1Service : IFlow
{
}
}

View File

@ -1,6 +1,4 @@
using Bullet6.Interfaces;
namespace Bullet6.Models
namespace Bullet6.Solution1.Models
{
public class Employee : IEntity
{

View File

@ -1,6 +1,4 @@
using Bullet6.Interfaces;
namespace Bullet6.Handlers
namespace Bullet6.Solution1.Models
{
public static class EntityHandler
{

View File

@ -1,4 +1,4 @@
namespace Bullet6.Interfaces
namespace Bullet6.Solution1.Models
{
public interface IEntity
{

View File

@ -1,6 +1,4 @@
using Bullet6.Interfaces;
namespace Bullet6.Models
namespace Bullet6.Solution1.Models
{
public class Manager : IEntity
{

View File

@ -0,0 +1,16 @@
using Bullet6.Solution1.Models;
namespace Bullet6.Solution1
{
public class Solution1Service : ISolution1Service
{
public Task Start()
{
Console.WriteLine($"{nameof(Solution1Service)} starting");
IEntity[] entites = [new Employee() { Name = "Ilias" }, new Manager() { Name = "Maria" }];
foreach (var entity in entites) EntityHandler.PrintName(entity);
Console.WriteLine($"{nameof(Solution1Service)} ended");
return Task.CompletedTask;
}
}
}

View File

@ -0,0 +1,7 @@
namespace Bullet6.Solution2
{
public interface ISolution2Service : IFlow
{
}
}

View File

@ -0,0 +1,10 @@
namespace Bullet6.Solution2.Models
{
public class Employee : Entity
{
protected override void PrintInternal()
{
// print the rest possible fields
}
}
}

View File

@ -0,0 +1,14 @@
namespace Bullet6.Solution2.Models
{
public abstract class Entity
{
public string Name { get; set; }
protected abstract void PrintInternal();
public void PrintName()
{
Console.WriteLine(this.Name);
this.PrintInternal();
}
}
}

View File

@ -0,0 +1,10 @@
namespace Bullet6.Solution2.Models
{
public class Manager : Entity
{
protected override void PrintInternal()
{
// print the rest possible fields
}
}
}

View File

@ -0,0 +1,16 @@
using Bullet6.Solution2.Models;
namespace Bullet6.Solution2
{
public class Solution2Service : ISolution2Service
{
public Task Start()
{
Console.WriteLine($"{nameof(Solution2Service)} starting");
Entity[] entites = [new Employee() { Name = "Ilias" }, new Manager() { Name = "Maria" }];
foreach (var entity in entites) entity.PrintName();
Console.WriteLine($"{nameof(Solution2Service)} ended");
return Task.CompletedTask;
}
}
}