Beispiel #1
0
        public override void RegisterCqrsHandlers(Assembly assembly)
        {
            var types = from type in assembly.GetTypes()
                        let handlerInterface = GetHandlerInterface(type)
                                               where handlerInterface != null
                                               select new { type, handlerInterface };

            foreach (var kvp in types)
            {
                _containerRegistrar.RegisterType(kvp.handlerInterface, kvp.type, Lifetime.Scoped);
                _containerRegistrar.Registrations.First(x => x.ConcreteType == kvp.type).AddService(kvp.type);
            }
        }
        /// <summary>
        /// Register all controllers
        /// </summary>
        /// <param name="registrar">The registrar</param>
        /// <param name="assembly">Assembly to scan.</param>
        public static void RegisterControllers(this IContainerRegistrar registrar, Assembly assembly)
        {
            var controllerType = typeof(IController);

            foreach (var type in assembly.GetTypes().Where(controllerType.IsAssignableFrom))
            {
                // no public constructors. A base class?
                if (type.GetConstructors().Length == 0 || type.IsAbstract)
                {
                    continue;
                }

                registrar.RegisterType(type, type, Lifetime.Transient);
            }
        }