using Autofac; using Autofac.Builder; using Kyoo.Abstractions.Controllers; using Microsoft.Extensions.Configuration; namespace Kyoo.Abstractions { /// /// 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 registration builder of this new task. That can be used to edit the registration. public static IRegistrationBuilder RegisterTask(this ContainerBuilder builder) where T : class, ITask { return builder.RegisterType().As(); } /// /// Register a new metadata provider to the container. /// /// The container /// The type of the task /// The registration builder of this new provider. That can be used to edit the registration. public static IRegistrationBuilder RegisterProvider(this ContainerBuilder builder) where T : class, IMetadataProvider { return builder.RegisterType().As().InstancePerLifetimeScope(); } /// /// 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 IRegistrationBuilder RegisterRepository(this ContainerBuilder builder) where T : IBaseRepository { return builder.RegisterType() .As() .As(Utility.GetGenericDefinition(typeof(T), typeof(IRepository<>))) .InstancePerLifetimeScope(); } /// /// Register a new repository with a custom mapping to the container. /// /// 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 IRegistrationBuilder RegisterRepository(this ContainerBuilder builder) where T2 : IBaseRepository, T { return builder.RegisterRepository().As(); } /// /// Get the public URL of kyoo using the given configuration instance. /// /// The configuration instance /// The public URl of kyoo (without a slash at the end) public static string GetPublicUrl(this IConfiguration configuration) { return configuration["basics:publicUrl"]?.TrimEnd('/') ?? "http://localhost:5000"; } } }