// // StatefulInjector.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using NosSmooth.Core.Client; namespace NosSmooth.Core.Stateful; /// /// The scoped injector of stateful entities. /// internal class StatefulInjector { private readonly StatefulRepository _repository; /// /// Initializes a new instance of the class. /// /// The repository of stateful entity types. public StatefulInjector(StatefulRepository repository) { _repository = repository; } /// /// Gets or sets the nostale client. /// public INostaleClient? Client { get; set; } /// /// Gets an entity of the specified type. /// /// The service provider. /// The type of the entity. /// Thrown if the client is not set. /// The entity to inject. public object GetEntity(IServiceProvider services, Type statefulEntityType) { if (Client is null) { throw new NullReferenceException("The client cannot be null in order to get a stateful entity."); } return _repository.GetEntity(services, Client, statefulEntityType); } }