Пример #1
0
        public IEnumerable <Type> GetAllHandlers(params Assembly[] assemblies)
        {
            List <Type> handlers = new List <Type>();

            var assembliesToScan = assemblies.Distinct().ToList();

            if (assembliesToScan.Count == 0)
            {
                assembliesToScan.Add(Assembly.GetExecutingAssembly());
            }

            foreach (var assembly in assembliesToScan)
            {
                var ttHandlers = assembly.DefinedTypes
                                 .Where(t => TypeTasqReference.IsConcrete(t) && TypeTasqReference.IsValidHandler(t))
                                 .Select(a => TypeTasqReference.Resolve(a))
                                 .ToList();

                foreach (var ttHandler in ttHandlers)
                {
                    handlers.Add(ttHandler.HandlerImplementation);
                }
            }

            return(handlers);
        }
Пример #2
0
        public virtual void RegisterFromAssembly(params Assembly[] assemblies)
        {
            var handlers = GetAllHandlers(assemblies);

            foreach (var handler in handlers)
            {
                Register(TypeTasqReference.Resolve(handler));
            }
        }
Пример #3
0
        public static TasqHandlerDetail TryGetFromType(Type type, ITasqHandlerResolver handlerResolver)
        {
            if (!TypeTasqReference.IsValidHandler(type))
            {
                return(null);
            }

            var reference = TypeTasqReference.Resolve(type);

            return(new TasqHandlerDetail
            {
                Handler = (ITasqHandler)handlerResolver.GetService(reference),
                Reference = reference
            });
        }
Пример #4
0
 public virtual void Register <THandler>() where THandler : ITasqHandler
 {
     Register(TypeTasqReference.Resolve <THandler>());
 }
Пример #5
0
 public virtual void Register(TypeTasqReference handler)
 {
     TasqHanders[handler.TasqProcess] = handler;
 }
Пример #6
0
 public virtual object GetService(TypeTasqReference typeTasqReference)
 {
     return(Activator.CreateInstance(typeTasqReference.HandlerImplementation));
 }