Код: Выделить всё
public class MyClass
{
private readonly ILogger _logger;
private Dictionary _instances;
public MyClass(ILogger logger, int count)
{
_instances = new Dictionary();
}
public void Operate(string id, int var1, string var2, ...)
{
if (!_instances.ContainsKey(id))
_instances.Add(id, new MyOtherClass(/* XXX */, var1, var2));
}
}
< /code>
public class MyOtherClass
{
private int _var1;
private string _var2;
private readonly ILogger _logger;
public MyOtherClass(ILogger logger, int var1, string var2)
{
_logger = logger;
_var1 = var1;
_var2 = var2;
}
}
< /code>
What's the best .Net Core C# way of achieving this instance creation? I am thinking of:
[list]
[*]Register and GetRequiredService()[*]
Код: Выделить всё
MyClassПодробнее здесь: https://stackoverflow.com/questions/797 ... d-services
Мобильная версия