Ejemplo n.º 1
0
        /// <summary>
        /// 向当前网站中注册配置信息。
        /// </summary>
        public static void Register()
        {
            // 初始化 IOC 配置
            var container = BuildUnityContainer();

            GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);

            // 加载缺省配置
            ConfigurationPipeline.ContainerConfiguration.Add(new AssemblyResolveConfiguration());
            ConfigurationPipeline.ContainerConfiguration.Add(new CustomConfigConfiguration());
            ConfigurationPipeline.ContainerConfiguration.Add(new UnityContainerConfiguration());

            ConfigurationPipeline.HttpConfiguration.Add(new AppConfigConfiguration());
            ConfigurationPipeline.HttpConfiguration.Add(new DefaultHttpRouteConfiguration());
            ConfigurationPipeline.HttpConfiguration.Add(new RequestConfiguration());
            ConfigurationPipeline.HttpConfiguration.Add(ConfigurationCreator.CreateHttpConfigurationFromDelegate(p =>
            {
                p.Filters.Add(new ReturnValueWrapperAttribute());
                p.Filters.Add(new ReturnExceptionWrapperAttribute());
            }));

            // 触发自定义初始化加载
            GlobalStarterX.Instance.RaiseEvent(p => p.Initialize());

            // 加载 IOC 配置
            ConfigurationPipeline.ContainerConfiguration.Aggregate((object)container, (x, y) => y.ConfigurateContainer(x));
            // 加载 其它 配置
            ConfigurationPipeline.HttpConfiguration.ForEach(p => p.Configurate(GlobalConfiguration.Configuration));

            // 触发配置完成事件
            GlobalStarterX.Instance.RaiseEvent(p => p.Complete());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 引发当前程序集的初始化操作:该操作在初始化 IOC 基本配置,加载默认的配置管道后触发,触发索引【1】。
        /// </summary>
        public override void Initialize()
        {
            ConfigurationPipeline.ContainerConfiguration.Add(ConfigurationCreator.CreateContainerConfigurationFromDelegate(container =>
            {
                var unity = container as IUnityContainer;

                var validator = new DefaultAuthenticationTokenValidator()
                {
                    SlideDue = TimeSpan.FromHours(2),
                };

                unity.RegisterType <IIdentity, DefaultIdentity>("Default")
                .RegisterType <IIdentity, UserTokenController>("UserToken")
                .RegisterInstance <IAuthenticationTokenRegister>(validator)
                .RegisterInstance <IAuthenticationTokenValidator>(validator);

                return(container);
            }));
            ConfigurationPipeline.HttpConfiguration.Add(ConfigurationCreator.CreateHttpConfigurationFromDelegate(configuration => configuration.Filters.Add(new PrincipalAuthorizationFilter())));
        }