diff --git a/src/Lib/Lionk.Core/Model/Services/ComponentService/ComponentService.cs b/src/Lib/Lionk.Core/Model/Services/ComponentService/ComponentService.cs
index 4fa32a1c..2494fe84 100644
--- a/src/Lib/Lionk.Core/Model/Services/ComponentService/ComponentService.cs
+++ b/src/Lib/Lionk.Core/Model/Services/ComponentService/ComponentService.cs
@@ -1,6 +1,7 @@
// Copyright © 2024 Lionk Project
using System.Collections.Concurrent;
+using System.Reflection;
using Lionk.Core.TypeRegistery;
namespace Lionk.Core.Component;
@@ -23,7 +24,10 @@ public ComponentService(ITypesProvider provider)
///
public void RegisterComponentInstance(IComponent component)
{
- string baseName = component.InstanceName ?? DefaultComponentName;
+ if (component.GetType().GetCustomAttribute() is NamedElement attribute)
+ component.InstanceName = attribute.Name;
+
+ string baseName = component.InstanceName == string.Empty ? DefaultComponentName : component.InstanceName;
string uniqueName = GenerateUniqueName(baseName);
component.InstanceName = uniqueName;
_componentInstances.TryAdd(uniqueName, component);
@@ -48,7 +52,7 @@ public IReadOnlyDictionary GetRegisteredTypeD
///
public IComponent? GetInstanceByName(string name)
{
- _componentInstances.TryGetValue(name, out IComponent? component);
+ IComponent? component = _componentInstances.Values.Where(x => x.InstanceName == name).FirstOrDefault();
return component;
}