コード例 #1
0
ファイル: WebApiConfig.cs プロジェクト: HZI-carol/vgoyun.com
        /// <summary>
        /// 预加载网站启动相关步骤
        /// </summary>
        public static void PreRegister()
        {
            var config = GlobalConfiguration.Configuration;
            var dict   = new Dictionary <Type, object>();

            dict.Add(typeof(string), "vgoyun.com");
            InjectionContainer.Register <SqlStorageBase>(typeof(UserStorage).Assembly, dict);
            //注册数据库模型验证类
            InjectionContainer.Register <IValidator>(typeof(IUserStorage).Assembly);
            InjectionContainer.Build((builder) =>
            {
                // Register your Web API controllers.
                builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
                // OPTIONAL: Register the Autofac filter provider.
                builder.RegisterWebApiFilterProvider(config);
            }, c => config.DependencyResolver = new AutofacWebApiDependencyResolver(c));
        }