Ejemplo n.º 1
0
        private void RegisterDefaultService(Type type, InterfaceImplementationDefaultAttribute attribute)
        {
            var fullName = type.FullName;

            _logger.LogInformation("ServiceFinder. Registering type {0} as default service", fullName);
            var interfaces = UtilReflection.GetCleanInterfaces(type);

            if (interfaces.Count == 0)
            {
                throw new InvalidOperationException(
                          "Tried to register service with default interface, but the service has no interfaces");
            }

            var interfaceType = interfaces[0];

            _injectionProvider.Add(interfaceType, type, attribute.LifetimeMode);
        }
Ejemplo n.º 2
0
        public void FindFactories()
        {
            foreach (var container in TypeListContainers)
            {
                if (container.IsInterface || container.IsAbstract)
                {
                    continue;
                }

                var pi         = container.GetProperty("TypeList");
                var interfaces = UtilReflection.GetCleanInterfaces(container);
                if (interfaces.Count != 1)
                {
                    continue;
                }

                var instance = ServiceLocator.GetService(interfaces[0]);
                var typeList = (IList <Type>)pi.GetValue(instance, null);
                foreach (var type in typeList)
                {
                    _injectionProvider.Add(type, type, LifetimeMode.Singleton);
                }
            }
        }