示例#1
0
        /// <summary>
        /// Registers a service with InstanceScope.PerLifetimeScope
        /// </summary>
        /// <typeparam name="TRegisterAs">Type to register the service as</typeparam>
        /// <typeparam name="TConcrete">Concrete type to register.</typeparam>
        /// <returns>The IContainerRegister instance for method chaining.</returns>
        public static IContainerRegister RegisterPerRequestScope <TRegisterAs, TConcrete>(this IContainerRegister container) where TConcrete : TRegisterAs
        {
            var options = new RegistrationOptions();

            options.InstanceScope = InstanceScope.PerLifetimeScope;
            return(container.RegisterType <TRegisterAs, TConcrete>(options));
        }
示例#2
0
        /// <summary>
        /// Registers a DbContext using the default convention, which is to use InstanceScope.PerLifetimeScope
        /// and register it as itself only.
        /// </summary>
        /// <returns>The IContainerRegister instance for method chaining.</returns>
        public static IContainerRegister RegisterDatabase <T>(this IContainerRegister container) where T : DbContext
        {
            var options = new RegistrationOptions();

            options.InstanceScope = InstanceScope.PerLifetimeScope;
            return(container.RegisterType <T, T>(options));
        }
示例#3
0
        /// <summary>
        /// A quick way of creatinf a new options set which sets the
        /// ReplaceExisting property to true
        /// </summary>
        /// <param name="overridePriority">Optionally specify an override priority</param>
        public static RegistrationOptions Override(RegistrationOverridePriority?overridePriority = null)
        {
            var options = new RegistrationOptions();

            if (overridePriority.HasValue)
            {
                options.RegistrationOverridePriority = (int)overridePriority;
            }

            return(options);
        }