1
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user