static void UpdateControllerService <T>(ServicesContainer services, IComponentContext container, ControllerTypeKey serviceKey) where T : class
        {
            var instance           = container.ResolveOptionalKeyed <Meta <T> >(serviceKey);
            var baseControllerType = serviceKey.ControllerType.BaseType;

            while (instance == null && baseControllerType != typeof(ApiController))
            {
                var baseServiceKey = new ControllerTypeKey(baseControllerType);
                instance           = container.ResolveOptionalKeyed <Meta <T> >(baseServiceKey);
                baseControllerType = baseServiceKey.ControllerType.BaseType;
            }

            if (instance != null)
            {
                services.Replace(typeof(T), instance.Value);
            }
        }
Esempio n. 2
0
        public static IEndPointValidator ResolveValidator(IComponentContext cxt, string endPointType, string providerName)
        {
            IEndPointValidator result = null;

            result = cxt.ResolveOptionalKeyed <IEndPointValidator>(endPointType + providerName);

            if (result == null)
            {
                throw new ComponentNotRegisteredException($"An attempt to resolve an EndPointValidator for EndPointType { endPointType } failed.  Use the RegisterEndPointValidator method on the RegistrationHelper to register an EndPointValidator for each EndPointType.");
            }

            return(result);
        }
Esempio n. 3
0
        public static IPerimeter ResolvePerimeter(IComponentContext cxt, Type typ)
        {
            IPerimeter result = null;

            result = cxt.ResolveOptionalKeyed <IPerimeter>(typ);

            if (result == null)
            {
                throw new ComponentNotRegisteredException($"Interface { typ.Name } has not been registered.  Use RegistrationHelper to register { typ.Name } with one or more implementations, EndPointConfiguration, and API names.");
            }

            return(result);
        }
Esempio n. 4
0
        private static void UpdateControllerFormatters(ICollection <MediaTypeFormatter> collection, IComponentContext container, ControllerTypeKey serviceKey)
        {
            var formatters = container.ResolveOptionalKeyed <IEnumerable <Meta <MediaTypeFormatter> > >(serviceKey).ToArray();

            if (formatters.Any(service => ClearExistingServices(service.Metadata)))
            {
                collection.Clear();
            }

            foreach (var formatter in formatters)
            {
                collection.Add(formatter.Value);
            }
        }
        static void UpdateControllerServices <T>(ServicesContainer services, IComponentContext container, ControllerTypeKey serviceKey) where T : class
        {
            var resolvedInstances = container.ResolveOptionalKeyed <IEnumerable <Meta <T> > >(serviceKey).ToArray();

            if (resolvedInstances.Any(service => ClearExistingServices(service.Metadata)))
            {
                services.Clear(typeof(T));
            }

            foreach (var instance in resolvedInstances)
            {
                services.Add(typeof(T), instance.Value);
            }
        }
Esempio n. 6
0
        public INodeViewModel Create(INodeViewModel parent, string nodeType)
        {
            IDocumentNodeFactory factory = _container.ResolveOptionalKeyed <IDocumentNodeFactory>(nodeType);

            if (factory == null)
            {
                factory = _container.ResolveKeyed <IDocumentNodeFactory>("default_node");
            }

            INodeViewModel node = factory.Create(parent, nodeType);

            if (parent != null)
            {
                parent.Children.Add(node);
            }

            return(node);
        }
Esempio n. 7
0
        private async Task <ISmtpCommand> GetCommandAsync(CancellationToken token)
        {
            string line = await _connection.ReadLineAsync(Encoding.UTF8, token);

            _log.Verbose($"SMTP <- {line}");
            if (line.Length < 4)
            {
                await this.SendReplyAsync(SmtpReplyCode.SyntaxError, "No command found", token);

                return(null);
            }

            int    spaceIndex = line.IndexOf(" ", StringComparison.Ordinal);
            string command;
            string arguments;

            if (spaceIndex == -1)
            {
                command   = line;
                arguments = null;
            }
            else
            {
                command   = line.Substring(0, spaceIndex).ToUpperInvariant();
                arguments = line.Substring(spaceIndex + 1);
            }

            var commandExecutor = _context.ResolveOptionalKeyed <ISmtpCommand>(command);

            if (commandExecutor == null)
            {
                await this.SendReplyAsync(SmtpReplyCode.SyntaxError, "Command not implemented", token);

                return(null);
            }

            commandExecutor.Initialize(arguments);

            return(commandExecutor);
        }
Esempio n. 8
0
 /// <summary>
 /// Retrieve a service from the context, or null if the service is not
 /// registered.
 /// </summary>
 /// <param name="context">The context from which to resolve the service.</param>
 /// <param name="parameters">Parameters for the service.</param>
 /// <param name="serviceKey">The key of the service.</param>
 /// <typeparam name="TService">The service to resolve.</typeparam>
 /// <returns>
 /// The component instance that provides the service, or null.
 /// </returns>
 /// <exception cref="DependencyResolutionException"/>
 public static TService ResolveOptionalKeyed <TService>(this IComponentContext context, object serviceKey, params Parameter[] parameters)
     where TService : class
 {
     return(context.ResolveOptionalKeyed <TService>(serviceKey, (IEnumerable <Parameter>)parameters));
 }
Esempio n. 9
0
 /// <summary>
 /// Retrieve a service from the context, or null if the service is not
 /// registered.
 /// </summary>
 /// <param name="context">The context from which to resolve the service.</param>
 /// <param name="parameters">Parameters for the service.</param>
 /// <param name="serviceName">The name of the service.</param>
 /// <typeparam name="TService">The service to resolve.</typeparam>
 /// <returns>
 /// The component instance that provides the service, or null.
 /// </returns>
 /// <exception cref="DependencyResolutionException"/>
 public static TService ResolveOptionalNamed <TService>(this IComponentContext context, string serviceName, params Parameter[] parameters)
     where TService : class
 {
     return(context.ResolveOptionalKeyed <TService>(serviceName, parameters));
 }
Esempio n. 10
0
 public IHandler <T> Resolve <T>() where T : IPersonCommand
 {
     return(_context.ResolveOptionalKeyed <IHandler <T> >("DecoratedHandler"));
 }
Esempio n. 11
0
 /// <summary>
 /// Retrieve a service from the context, or null if the service is not
 /// registered.
 /// </summary>
 /// <param name="context">The context from which to resolve the service.</param>
 /// <param name="serviceKey">The name of the service.</param>
 /// <typeparam name="TService">The service to resolve.</typeparam>
 /// <returns>
 /// The component instance that provides the service, or null.
 /// </returns>
 /// <exception cref="DependencyResolutionException"/>
 public static TService?ResolveOptionalKeyed <TService>(this IComponentContext context, object serviceKey)
     where TService : struct
 {
     return(context.ResolveOptionalKeyed <TService>(serviceKey, NoParameters));
 }