Multiple solutions for bullet 6.
This commit is contained in:
parent
b03a58fc92
commit
15df86fad7
|
|
@ -7,4 +7,8 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
public interface IFlow
|
||||||
|
{
|
||||||
|
Task Start();
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,25 @@
|
||||||
using Bullet6.Handlers;
|
using Bullet6.Solution1;
|
||||||
using Bullet6.Interfaces;
|
using Bullet6.Solution2;
|
||||||
using Bullet6.Models;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Bullet6
|
namespace Bullet6
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
IEntity[] entites = [new Employee() { Name = "Ilias" }, new Manager() { Name = "Maria" }];
|
ServiceCollection services = new ServiceCollection();
|
||||||
foreach (var entity in entites) EntityHandler.PrintName(entity);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Bullet6.Solution1
|
||||||
|
{
|
||||||
|
public interface ISolution1Service : IFlow
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
using Bullet6.Interfaces;
|
namespace Bullet6.Solution1.Models
|
||||||
|
|
||||||
namespace Bullet6.Models
|
|
||||||
{
|
{
|
||||||
public class Employee : IEntity
|
public class Employee : IEntity
|
||||||
{
|
{
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
using Bullet6.Interfaces;
|
namespace Bullet6.Solution1.Models
|
||||||
|
|
||||||
namespace Bullet6.Handlers
|
|
||||||
{
|
{
|
||||||
public static class EntityHandler
|
public static class EntityHandler
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Bullet6.Interfaces
|
namespace Bullet6.Solution1.Models
|
||||||
{
|
{
|
||||||
public interface IEntity
|
public interface IEntity
|
||||||
{
|
{
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
using Bullet6.Interfaces;
|
namespace Bullet6.Solution1.Models
|
||||||
|
|
||||||
namespace Bullet6.Models
|
|
||||||
{
|
{
|
||||||
public class Manager : IEntity
|
public class Manager : IEntity
|
||||||
{
|
{
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Bullet6.Solution2
|
||||||
|
{
|
||||||
|
public interface ISolution2Service : IFlow
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
namespace Bullet6.Solution2.Models
|
||||||
|
{
|
||||||
|
public class Employee : Entity
|
||||||
|
{
|
||||||
|
protected override void PrintInternal()
|
||||||
|
{
|
||||||
|
// print the rest possible fields
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
namespace Bullet6.Solution2.Models
|
||||||
|
{
|
||||||
|
public class Manager : Entity
|
||||||
|
{
|
||||||
|
protected override void PrintInternal()
|
||||||
|
{
|
||||||
|
// print the rest possible fields
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue