示例#1
0
        public static IComponentConfigurator <IdentityContext> Identity(this IRegistration registration)
        {
            var configurator = new ComponentConfigurator <IdentityContext>(registration, new IdentityContext());

            configurator.Configure(c =>
            {
                c.ClaimType = typeof(IdentityUserClaim <>);
            });

            configurator.Register((r, c) =>
            {
                Type userClaimType = c.ClaimType.MakeGenericType(c.UserType);

                Type userStoreInterface = typeof(IUserStore <,>).MakeGenericType(c.UserType, typeof(Guid));

                Type userStoreClass = typeof(UserStore <, ,>).MakeGenericType(c.UserType, c.RoleType, userClaimType);

                Type userManagerBase  = typeof(UserManager <,>).MakeGenericType(c.UserType, typeof(Guid));
                Type userManagerClass = c.UserManagerType ?? typeof(UserManager <,>).MakeGenericType(c.UserType, typeof(Guid));

                r.For(userStoreInterface).To(userStoreClass).LifeTime(c.LifeTime);
                r.For(userManagerBase).To(userManagerClass).LifeTime(c.LifeTime);
            });
            return(configurator);
        }
示例#2
0
        public static IComponentConfigurator <HibernateDataContext> HibernateDataSource <T>(this IRegistration registration, LifeTime lifeTime = LifeTime.Transient)
        {
            var configurator = new ComponentConfigurator <HibernateDataContext>(registration);

            #region Configure default values
            configurator.Configure(c => c.LifeTime  = lifeTime);
            configurator.Configure(c => c.DbContext = typeof(T));
            #endregion

            configurator.Register((r, c) =>
            {
                var name = c.Name;

                if (string.IsNullOrEmpty(name))
                {
                    name = Guid.NewGuid().ToString();
                }

                var dataSourceNameSet  = string.Format("{0}_hdatasource", name);
                var sessionFactoryName = string.Format("{0}_sessionfactory", dataSourceNameSet);
                var sessionName        = string.Format("{0}_session", dataSourceNameSet);

                r.For <ISessionFactory>().ToFactory(fc => GetSessionFactory(c)).Name(sessionFactoryName).LifeTime(LifeTime.Singleton);
                r.For <ISession>().ToFactory((fc, resolver) =>
                {
                    var factoryName = sessionFactoryName;
                    var factory     = resolver.Resolve <ISessionFactory>(factoryName);
                    return(factory.OpenSession());
                }).DependsOnComponent <ISessionFactory>(sessionFactoryName).Name(sessionName).LifeTime(c.LifeTime);

                r.For <IDataSource>().To <HibernateDataSource>().DependsOnComponent <ISession>(sessionName).Name(name).LifeTime(c.LifeTime);
            });
            return(configurator);
        }
示例#3
0
        public static IComponentConfigurator <ControllersContext> Controllers <T>(this IRegistration registrator) where T : class
        {
            var configurator = new ComponentConfigurator <ControllersContext>(registrator);

            configurator.Register((r, c) => r.Type().Assemblies(c.Assemblies.ToArray()).Where(x => x.BasedOn(c.ControllerType)).LifeTime(c.LifeTime));
            configurator.Configure(c => c.ControllerType = typeof(T));
            return(configurator);
        }
示例#4
0
        public static IComponentConfigurator <LoggerContext> UseLog4Net(this IRegistration registration)
        {
            var configurator = new ComponentConfigurator <LoggerContext>(registration);

            configurator.Register((r, c) => r.For <ILogger>()
                                  .Intercept.Method <ILogger>(m => m.Info(default(string)), context => GetLogger(context.ResolverType.FullName).Info(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Trace(default(string)), context => GetLogger(context.ResolverType.FullName).Info(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Warn(default(string)), context => GetLogger(context.ResolverType.FullName).Warn(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Debug(default(string)), context => GetLogger(context.ResolverType.FullName).Debug(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Error(default(string)), context => GetLogger(context.ResolverType.FullName).Error(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Info(default(string), default(string[])), context => GetLogger(context.ResolverType.FullName).Info(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Trace(default(string), default(string[])), context => GetLogger(context.ResolverType.FullName).Info(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Warn(default(string), default(string[])), context => GetLogger(context.ResolverType.FullName).Warn(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Debug(default(string), default(string[])), context => GetLogger(context.ResolverType.FullName).Debug(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Error(default(string), default(string[])), context => GetLogger(context.ResolverType.FullName).Error(context.Arguments[0] as string))
                                  .Intercept.Method <ILogger>(m => m.Error(default(string), default(Exception)), context => GetLogger(context.ResolverType.FullName).Error(context.Arguments[0] as string, context.Arguments[1] as Exception)));
            return(configurator);
        }
示例#5
0
        public static IComponentConfigurator <SitemapContext> SiteMap(this IRegistration registration)
        {
            var componentConfigurator = new ComponentConfigurator <SitemapContext>(registration, new SitemapContext());

            componentConfigurator.Configure(c => c.NodeType = typeof(SitemapNode));
            componentConfigurator.Register((r, c) =>
            {
                var readerServiceType = typeof(ISitemapReader <>).MakeGenericType(c.NodeType);
                var readerImplType    = typeof(SitemapFileReader <>).MakeGenericType(c.NodeType);

                var managerServiceType = typeof(ISitemapManager <>).MakeGenericType(c.NodeType);
                var managerImplType    = typeof(SitemapManager <>).MakeGenericType(c.NodeType);

                var readername = string.Format("sitemapreader_{0}", Guid.NewGuid().ToString());
                r.For(readerServiceType).To(readerImplType).DependsOnValue("path", c.Source).Name(readername).LifeTime(LifeTime.Singleton);
                r.For(managerServiceType).To(managerImplType).DependsOnComponent(readerServiceType, readername).LifeTime(LifeTime.Singleton);
            });
            return(componentConfigurator);
        }
示例#6
0
        public static IComponentConfigurator <StoreContext> Repository(this IRegistration registration)
        {
            var configurator = new ComponentConfigurator <StoreContext>(registration, new StoreContext());

            configurator.Configure(c => c.StoreClass = typeof(Store <>));
            configurator.Register((r, c) =>
            {
                var name = c.Name;
                if (string.IsNullOrEmpty(name))
                {
                    name = Guid.NewGuid().ToString();
                }

                var registrating = r.For(typeof(IStore <>)).To(c.StoreClass);
                if (c.Interceptor != null)
                {
                    c.Interceptor(registrating.Intercept);
                }
                registrating.DependsOnComponent <IDataSource>(c.DataSource).Name(name).LifeTime(c.LifeTime);
            });
            return(configurator);
        }