Register and construct DtoService correctly
This commit is contained in:
parent
cb2d99e831
commit
75b05ca1e6
|
@ -271,10 +271,6 @@ namespace Emby.Server.Implementations
|
||||||
/// <value>The provider manager.</value>
|
/// <value>The provider manager.</value>
|
||||||
private IProviderManager ProviderManager { get; set; }
|
private IProviderManager ProviderManager { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private IDtoService DtoService { get; set; }
|
|
||||||
|
|
||||||
public IImageProcessor ImageProcessor { get; set; }
|
public IImageProcessor ImageProcessor { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -711,7 +707,7 @@ namespace Emby.Server.Implementations
|
||||||
XmlSerializer,
|
XmlSerializer,
|
||||||
NetworkManager,
|
NetworkManager,
|
||||||
() => ImageProcessor,
|
() => ImageProcessor,
|
||||||
() => DtoService,
|
Resolve<IDtoService>,
|
||||||
this,
|
this,
|
||||||
JsonSerializer,
|
JsonSerializer,
|
||||||
FileSystemManager,
|
FileSystemManager,
|
||||||
|
@ -766,8 +762,9 @@ namespace Emby.Server.Implementations
|
||||||
ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, LoggerFactory, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer);
|
ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, LoggerFactory, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer);
|
||||||
serviceCollection.AddSingleton(ProviderManager);
|
serviceCollection.AddSingleton(ProviderManager);
|
||||||
|
|
||||||
DtoService = new DtoService(LoggerFactory, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ProviderManager, this, () => MediaSourceManager, () => _liveTvManager);
|
// TODO: Refactor to eliminate circular dependency here so Lazy<> isn't required
|
||||||
serviceCollection.AddSingleton(DtoService);
|
serviceCollection.AddTransient(provider => new Lazy<ILiveTvManager>(provider.GetRequiredService<ILiveTvManager>));
|
||||||
|
serviceCollection.AddSingleton<IDtoService, DtoService>();
|
||||||
|
|
||||||
serviceCollection.AddSingleton<IChannelManager, ChannelManager>();
|
serviceCollection.AddSingleton<IChannelManager, ChannelManager>();
|
||||||
|
|
||||||
|
|
|
@ -38,21 +38,23 @@ namespace Emby.Server.Implementations.Dto
|
||||||
private readonly IProviderManager _providerManager;
|
private readonly IProviderManager _providerManager;
|
||||||
|
|
||||||
private readonly IApplicationHost _appHost;
|
private readonly IApplicationHost _appHost;
|
||||||
private readonly Func<IMediaSourceManager> _mediaSourceManager;
|
private readonly IMediaSourceManager _mediaSourceManager;
|
||||||
private readonly Func<ILiveTvManager> _livetvManager;
|
private readonly Lazy<ILiveTvManager> _livetvManagerLazy;
|
||||||
|
|
||||||
|
private ILiveTvManager LivetvManager => _livetvManagerLazy.Value;
|
||||||
|
|
||||||
public DtoService(
|
public DtoService(
|
||||||
ILoggerFactory loggerFactory,
|
ILogger<DtoService> logger,
|
||||||
ILibraryManager libraryManager,
|
ILibraryManager libraryManager,
|
||||||
IUserDataManager userDataRepository,
|
IUserDataManager userDataRepository,
|
||||||
IItemRepository itemRepo,
|
IItemRepository itemRepo,
|
||||||
IImageProcessor imageProcessor,
|
IImageProcessor imageProcessor,
|
||||||
IProviderManager providerManager,
|
IProviderManager providerManager,
|
||||||
IApplicationHost appHost,
|
IApplicationHost appHost,
|
||||||
Func<IMediaSourceManager> mediaSourceManager,
|
IMediaSourceManager mediaSourceManager,
|
||||||
Func<ILiveTvManager> livetvManager)
|
Lazy<ILiveTvManager> livetvManager)
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.CreateLogger(nameof(DtoService));
|
_logger = logger;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_userDataRepository = userDataRepository;
|
_userDataRepository = userDataRepository;
|
||||||
_itemRepo = itemRepo;
|
_itemRepo = itemRepo;
|
||||||
|
@ -60,7 +62,7 @@ namespace Emby.Server.Implementations.Dto
|
||||||
_providerManager = providerManager;
|
_providerManager = providerManager;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
_mediaSourceManager = mediaSourceManager;
|
_mediaSourceManager = mediaSourceManager;
|
||||||
_livetvManager = livetvManager;
|
_livetvManagerLazy = livetvManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -125,12 +127,12 @@ namespace Emby.Server.Implementations.Dto
|
||||||
|
|
||||||
if (programTuples.Count > 0)
|
if (programTuples.Count > 0)
|
||||||
{
|
{
|
||||||
_livetvManager().AddInfoToProgramDto(programTuples, options.Fields, user).GetAwaiter().GetResult();
|
LivetvManager.AddInfoToProgramDto(programTuples, options.Fields, user).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channelTuples.Count > 0)
|
if (channelTuples.Count > 0)
|
||||||
{
|
{
|
||||||
_livetvManager().AddChannelInfo(channelTuples, options, user);
|
LivetvManager.AddChannelInfo(channelTuples, options, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnItems;
|
return returnItems;
|
||||||
|
@ -142,12 +144,12 @@ namespace Emby.Server.Implementations.Dto
|
||||||
if (item is LiveTvChannel tvChannel)
|
if (item is LiveTvChannel tvChannel)
|
||||||
{
|
{
|
||||||
var list = new List<(BaseItemDto, LiveTvChannel)>(1) { (dto, tvChannel) };
|
var list = new List<(BaseItemDto, LiveTvChannel)>(1) { (dto, tvChannel) };
|
||||||
_livetvManager().AddChannelInfo(list, options, user);
|
LivetvManager.AddChannelInfo(list, options, user);
|
||||||
}
|
}
|
||||||
else if (item is LiveTvProgram)
|
else if (item is LiveTvProgram)
|
||||||
{
|
{
|
||||||
var list = new List<(BaseItem, BaseItemDto)>(1) { (item, dto) };
|
var list = new List<(BaseItem, BaseItemDto)>(1) { (item, dto) };
|
||||||
var task = _livetvManager().AddInfoToProgramDto(list, options.Fields, user);
|
var task = LivetvManager.AddInfoToProgramDto(list, options.Fields, user);
|
||||||
Task.WaitAll(task);
|
Task.WaitAll(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +225,7 @@ namespace Emby.Server.Implementations.Dto
|
||||||
if (item is IHasMediaSources
|
if (item is IHasMediaSources
|
||||||
&& options.ContainsField(ItemFields.MediaSources))
|
&& options.ContainsField(ItemFields.MediaSources))
|
||||||
{
|
{
|
||||||
dto.MediaSources = _mediaSourceManager().GetStaticMediaSources(item, true, user).ToArray();
|
dto.MediaSources = _mediaSourceManager.GetStaticMediaSources(item, true, user).ToArray();
|
||||||
|
|
||||||
NormalizeMediaSourceContainers(dto);
|
NormalizeMediaSourceContainers(dto);
|
||||||
}
|
}
|
||||||
|
@ -254,7 +256,7 @@ namespace Emby.Server.Implementations.Dto
|
||||||
dto.Etag = item.GetEtag(user);
|
dto.Etag = item.GetEtag(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
var liveTvManager = _livetvManager();
|
var liveTvManager = LivetvManager;
|
||||||
var activeRecording = liveTvManager.GetActiveRecordingInfo(item.Path);
|
var activeRecording = liveTvManager.GetActiveRecordingInfo(item.Path);
|
||||||
if (activeRecording != null)
|
if (activeRecording != null)
|
||||||
{
|
{
|
||||||
|
@ -1045,7 +1047,7 @@ namespace Emby.Server.Implementations.Dto
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mediaStreams = _mediaSourceManager().GetStaticMediaSources(item, true)[0].MediaStreams.ToArray();
|
mediaStreams = _mediaSourceManager.GetStaticMediaSources(item, true)[0].MediaStreams.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
dto.MediaStreams = mediaStreams;
|
dto.MediaStreams = mediaStreams;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user