~ruther/NosSmooth

ref: 0eb703efa82e664df7d46a746f7d5fbe6a853b51 NosSmooth/Core/NosSmooth.Core/Stateful/StatefulInjector.cs -rw-r--r-- 1.5 KiB
0eb703ef — František Boháček fix(packets): change context list attribute generator to respect current api 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
//  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;

/// <summary>
/// The scoped injector of stateful entities.
/// </summary>
internal class StatefulInjector
{
    private readonly StatefulRepository _repository;

    /// <summary>
    /// Initializes a new instance of the <see cref="StatefulInjector"/> class.
    /// </summary>
    /// <param name="repository">The repository of stateful entity types.</param>
    public StatefulInjector(StatefulRepository repository)
    {
        _repository = repository;
    }

    /// <summary>
    /// Gets or sets the nostale client.
    /// </summary>
    public INostaleClient? Client { get; set; }

    /// <summary>
    /// Gets an entity of the specified type.
    /// </summary>
    /// <param name="services">The service provider.</param>
    /// <param name="statefulEntityType">The type of the entity.</param>
    /// <exception cref="NullReferenceException">Thrown if the client is not set.</exception>
    /// <returns>The entity to inject.</returns>
    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);
    }
}
Do not follow this link