/// <summary>
        /// Registers the <see cref="IHub"/> implementations found in the given types.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="types">The types.</param>
        /// <returns>The container.</returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer RegisterHubs(this IStashboxContainer container, params Type[] types)
        {
            Shield.EnsureNotNull(container, nameof(container));

            if (types.Length > 0)
            {
                container.RegisterTypes(types, type => typeof(IHub).IsAssignableFrom(type), context => context.WithoutDisposalTracking());
            }

            return(container);
        }
Beispiel #2
0
        /// <summary>
        /// Registers the web api controllers into the <see cref="IStashboxContainer"/>.
        /// </summary>
        /// <param name="config">The http configuration.</param>
        /// <param name="container">The container.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="container"/> or <paramref name="config"/> is <c>null</c>.
        /// </exception>
        public static IStashboxContainer RegisterWebApiControllers(this IStashboxContainer container, HttpConfiguration config)
        {
            Shield.EnsureNotNull(container, nameof(container));
            Shield.EnsureNotNull(config, nameof(config));

            var assembliesResolver = config.Services.GetAssembliesResolver();
            var typeResolver       = config.Services.GetHttpControllerTypeResolver();

            container.RegisterTypes(typeResolver.GetControllerTypes(assembliesResolver), null,
                                    context => context.WithLifetime(new ScopedLifetime()));

            return(container);
        }