using System;
using Kyoo.Controllers;
using Unity;
namespace Kyoo
{
///
/// A static class with helper functions to setup external modules
///
public static class Module
{
///
/// Register a new task to the container.
///
/// The container
/// The type of the task
/// The initial container.
public static IUnityContainer RegisterTask(this IUnityContainer container)
where T : class, ITask
{
container.RegisterType();
return container;
}
///
/// Register a new repository to the container.
///
/// The container
/// The type of the repository.
///
/// If your repository implements a special interface, please use
///
/// The initial container.
public static IUnityContainer RegisterRepository(this IUnityContainer container)
where T : IBaseRepository
{
Type repository = Utility.GetGenericDefinition(typeof(T), typeof(IRepository<>));
if (repository != null)
{
container.RegisterType(repository, typeof(T));
container.RegisterType(repository.FriendlyName());
}
else
container.RegisterType(typeof(T).FriendlyName());
return container;
}
///
/// Register a new repository with a custom mapping to the container.
///
///
/// The custom mapping you have for your repository.
/// The type of the repository.
///
/// If your repository does not implements a special interface, please use
///
/// The initial container.
public static IUnityContainer RegisterRepository(this IUnityContainer container)
where T2 : IBaseRepository, T
{
container.RegisterType();
return container.RegisterRepository();
}
}
}