-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for EasyMicroservices.Cores.Infrastructure
- Loading branch information
1 parent
0ef301e
commit 29853e5
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...harp/EasyMicroservices.Cores.Infrastructure/EasyMicroservices.Cores.Infrastructure.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1;net45;net6.0;net8.0</TargetFrameworks> | ||
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<Authors>EasyMicroservices</Authors> | ||
<Version>0.0.1.50</Version> | ||
<Description>core of infrastructure.</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>core,cores,base,infrastructure</PackageTags> | ||
<PackageProjectUrl>https://github.com/EasyMicroservices/Cores</PackageProjectUrl> | ||
<LangVersion>latest</LangVersion> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<RootNamespace>EasyMicroservices.Cores</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="EasyMicroservices.Utilities" Version="0.0.0.13" /> | ||
</ItemGroup> | ||
|
||
</Project> |
14 changes: 14 additions & 0 deletions
14
src/CSharp/EasyMicroservices.Cores.Infrastructure/Interfaces/IWidget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace EasyMicroservices.Cores.Interfaces; | ||
public interface IWidget | ||
{ | ||
void Build(); | ||
Type GetObjectType(); | ||
} | ||
|
||
public interface IWidget<T>: IWidget | ||
{ | ||
Task Initialize(params T[] parameters); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/CSharp/EasyMicroservices.Cores.Infrastructure/Interfaces/IWidgetManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace EasyMicroservices.Cores.Interfaces; | ||
|
||
public interface IWidgetManager | ||
{ | ||
void Register(IWidget widget); | ||
void UnRegister(IWidget widget); | ||
IEnumerable<IWidget> GetWidgetsByType(Type type); | ||
IEnumerable<T> GetWidgets<T>() | ||
where T : IWidget; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/CSharp/EasyMicroservices.Cores.Infrastructure/Widgets/WidgetManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using EasyMicroservices.Cores.Interfaces; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace EasyMicroservices.Cores.Widgets; | ||
public class WidgetManager : IWidgetManager | ||
{ | ||
readonly ConcurrentDictionary<Type, List<IWidget>> Widgets = new ConcurrentDictionary<Type, List<IWidget>>(); | ||
|
||
public void Register(IWidget widget) | ||
{ | ||
var type = widget.GetObjectType(); | ||
if (Widgets.TryGetValue(type, out List<IWidget> widgets)) | ||
widgets.Add(widget); | ||
else | ||
{ | ||
Widgets.TryAdd(widget.GetObjectType(), new List<IWidget>() | ||
{ | ||
widget | ||
}); | ||
} | ||
} | ||
|
||
public void UnRegister(IWidget widget) | ||
{ | ||
Widgets.TryRemove(widget.GetObjectType(), out _); | ||
} | ||
|
||
public IEnumerable<IWidget> GetWidgetsByType(Type type) | ||
{ | ||
if (Widgets.TryGetValue(type, out List<IWidget> widgets)) | ||
return widgets.ToList(); | ||
return Enumerable.Empty<IWidget>(); | ||
} | ||
|
||
public IEnumerable<T> GetWidgets<T>() where T : IWidget | ||
{ | ||
if (Widgets.TryGetValue(typeof(T), out List<IWidget> widgets)) | ||
return widgets.Cast<T>().ToList(); | ||
return Enumerable.Empty<T>(); | ||
} | ||
} |