예제 #1
0
 /// <summary>
 /// Create module instance.
 /// </summary>
 /// <param name="host"></param>
 protected Module(IModuleHost host)
 {
     Host      = host;
     Services  = host.Services;
     Logger    = Services.GetRequiredService <ILogger <Module> >();
     _manifest = new Lazy <ModuleManifest>(() => Host.GetManifest(GetType()));
 }
예제 #2
0
        /// <summary>
        /// Get option that belongs to the module.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="host"></param>
        /// <param name="provider"></param>
        /// <param name="moduleType"></param>
        /// <returns></returns>
        public static T GetOption <T>(this IModuleHost host, IServiceProvider provider, Type moduleType) where T : class
        {
            var manifest = host.GetManifest(moduleType);
            var type     = typeof(T);

            return(manifest.Options.Any(x => x == type)
                ? provider.GetRequiredService <IOptionsSnapshot <T> >().Value
                : throw new ModuleNotFoundException($"No such option for the module {moduleType.FullName}: {type.FullName}."));
        }
예제 #3
0
        /// <summary>
        /// Get service that belongs to the module.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="host"></param>
        /// <param name="provider"></param>
        /// <param name="moduleType"></param>
        /// <returns></returns>
        public static T GetService <T>(this IModuleHost host, IServiceProvider provider, Type moduleType) where T : notnull
        {
            var manifest = host.GetManifest(moduleType);
            var type     = typeof(T);

            return(manifest.Services.Any(x => x.ServiceType == type)
                ? provider.GetRequiredService <T>()
                : throw new ModuleNotFoundException($"No such service for the module {moduleType.FullName}: {type.FullName}."));
        }
예제 #4
0
        public static IModuleHost HasServices <T>(this IModuleHost host) where T : IModule
        {
            host.HasModule <T>();
            var manifest = host.GetManifest <T>();

            foreach (var item in manifest.Services)
            {
                host.HasService(item.ServiceType);
            }
            return(host);
        }
예제 #5
0
        public static IModuleHost HasDependencies <T>(this IModuleHost host) where T : IModule
        {
            host.HasModule <T>();
            var manifest = host.GetManifest <T>();

            foreach (var item in manifest.Dependencies)
            {
                host.HasModule(item);
            }
            return(host);
        }
예제 #6
0
 /// <summary>
 /// Get manifest for the module.
 /// </summary>
 /// <typeparam name="TModule"></typeparam>
 /// <param name="host"></param>
 /// <returns></returns>
 public static ModuleManifest GetManifest <TModule>(this IModuleHost host) where TModule : IModule => host.GetManifest(typeof(TModule));