refactor: Exception and init of dictionary
This commit is contained in:
parent
76991338f3
commit
3602d74eb4
1 changed files with 4 additions and 3 deletions
|
@ -10,7 +10,7 @@ namespace Server.Services;
|
|||
|
||||
public class ItemObjectPoolService : IHostedService
|
||||
{
|
||||
readonly ConcurrentDictionary<uint, ItemObject> _itemObjectPool = new();
|
||||
readonly ConcurrentDictionary<uint, ItemObject> _itemObjectPool;
|
||||
private readonly ItemReader _itemReader;
|
||||
private readonly ILogger<ItemObjectPoolService> _logger;
|
||||
|
||||
|
@ -19,6 +19,8 @@ public class ItemObjectPoolService : IHostedService
|
|||
_logger = logger;
|
||||
_itemReader = new ItemReader(configuration.GetSection("Game").GetSection("Data").GetValue<string>("Path") ??
|
||||
string.Empty);
|
||||
|
||||
_itemObjectPool = new ConcurrentDictionary<uint, ItemObject>();
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
|
@ -30,7 +32,7 @@ public class ItemObjectPoolService : IHostedService
|
|||
var result = _itemObjectPool.TryAdd(itemObject.ItemID, itemObject);
|
||||
if (!result)
|
||||
{
|
||||
throw new Exception($"Failed to add item {itemObject.ItemID} to the item object pool");
|
||||
throw new KeyNotFoundException($"Failed to add item {itemObject.ItemID} to the item object pool");
|
||||
}
|
||||
|
||||
_logger.LogTrace("Item with {ID} has been added", itemObject.ItemID);
|
||||
|
@ -43,7 +45,6 @@ public class ItemObjectPoolService : IHostedService
|
|||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue