This commit is contained in:
CortexCore
2025-03-09 13:38:23 +08:00
parent 8261a458e2
commit 18239a5ae4
67 changed files with 8573 additions and 831 deletions

View File

@@ -8,24 +8,24 @@ namespace BITKit.Entities
{
public class Entity : IEntity, IDisposable
{
public Entity()
{
ServiceCollection.AddSingleton<IEntity>(this);
}
public void WaitForInitializationComplete()
{
throw new NotImplementedException();
}
public int Id { get; set; } = Guid.NewGuid().GetHashCode();
public CancellationToken CancellationToken => _cancellationTokenSource.Token;
private readonly CancellationTokenSource _cancellationTokenSource = new();
public CancellationToken CancellationToken { get; set; }
public IServiceProvider ServiceProvider => _serviceProvider ??= ServiceCollection.BuildServiceProvider();
private ServiceProvider _serviceProvider;
public IServiceCollection ServiceCollection { get; } = new ServiceCollection();
public IServiceCollection ServiceCollection
{
get
{
if (_serviceCollection is not null) return _serviceCollection;
_serviceCollection = new ServiceCollection();
_serviceCollection.AddSingleton<IEntity>(this);
return _serviceCollection;
}
}
private IServiceCollection _serviceCollection;
public object[] GetServices() => ServiceCollection.ToArray()
.Select(x => _serviceProvider.GetService(x.ServiceType)).ToArray();
public void Inject(object obj)
{
foreach (var fieldInfo in obj.GetType().GetFields(ReflectionHelper.Flags))
@@ -39,7 +39,6 @@ namespace BITKit.Entities
public void Dispose()
{
_cancellationTokenSource.Cancel();
_serviceProvider.Dispose();
}
}