Click here to Skip to main content
15,851,131 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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.
Posted
Updated 25-Aug-19 7:47am
v2
Comments
Gerry Schmitz 25-Aug-19 17:25pm    
Looks over-engineered. Use "custom" collections only when the "generics" won't work (which is almost NEVER).
Member 11380736 26-Aug-19 8:50am    
I need to use a custom list

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900