I'm trying to create a dynamic architecture for a Audio/Video player application.
I want to be able to change the type of playlist and type of repository from inside the ioc container.
This should be injected in constructors around the application:
IPlaylist<IMedia> playlist, IRepository<IPlaylist<IMedia>> playlistRepository
I currently am able to change the playlist type but I'm having problems figuring out a solution for registering the repository dependency correctly.
Generic IPlaylist:
public interface IPlaylist<TMedia> where TMedia : IMedia
{
string PlaylistName { get; set; }
IList<TMedia> Media { get; set; }
}
SongPlaylist:
public class SongPlaylist: IPlaylist<Song>
{
public string PlaylistName { get; set; }
public IList<Song> Media { get; set; }
}
MediaPlaylist for both songs and videos:
public class MediaPlaylist : IPlaylist<Media>
{
public string PlaylistName { get; set; }
public IList<Media> Media { get; set; }
}
}
Repository interface:
public abstract class RepositoryBase<TConnection, TEntity> : IRepository<TEntity> where TEntity : class
Repository for songs:
public class SongPlaylistRepository : RepositoryBase<SignalRConnection, IPlaylist<Song>>
Repository for songs and videos:
public class MediaPlaylistRepository : RepositoryBase<SignalRConnection, IPlaylist<Media>>
Dryioc container: Here I register the generic IPlaylist which works:
containerRegistry.Register(typeof(IPlaylist<>), typeof(SongPlaylist));
This is what I would like to do, but I get "unexpected use of an unbound generic name":
containerRegistry.RegisterInstance<IRepository<IPlaylist<>>>(new SongPlaylistRepository(new SignalRConnection(new HubConnection("https://webapiaddress.com/"), "hub")));
What I have tried:
I've tried a lot of different things but I can't figure out if my architecture is way off or if I'm just not using the dependency injection container appropriate.