当前位置: 首页>>代码示例>>C#>>正文


C# Resolver.RegisterTypes方法代码示例

本文整理汇总了C#中Resolver.RegisterTypes方法的典型用法代码示例。如果您正苦于以下问题:C# Resolver.RegisterTypes方法的具体用法?C# Resolver.RegisterTypes怎么用?C# Resolver.RegisterTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Resolver的用法示例。


在下文中一共展示了Resolver.RegisterTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Register

        internal static void Register(HttpConfiguration config)
        {
            var container = new UnityContainer();
            config.DependencyResolver = new UnityResolver(container);

            Resolver resolver = new Resolver();
            resolver.RegisterTypes(container);

            config.MapHttpAttributeRoutes();

            config.Filters.Add(new GenericExceptionFilterAttribute());

            config.Filters.Add(new LogAttribute("SignboardApi", 500));
        }
开发者ID:hendrikdelarey,项目名称:appcampus,代码行数:14,代码来源:WebApiConfig.cs

示例2: Register

        internal static void Register(HttpConfiguration config)
        {
            // IOC container
            var container = new UnityContainer();
            config.DependencyResolver = new UnityResolver(container);

            // IOC resolution
            Resolver resolver = new Resolver();
            resolver.RegisterTypes(container);

            // Logger
            var logger = container.Resolve<ILoggingComponent>();
            logger.LogInfo(MethodBase.GetCurrentMethod(), "Web Api configuration started.");

            //var cors = new EnableCorsAttribute("localhost:50937,localhost:80", "*", "*");
            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);

            // Ignore any authentication which happens before the Web API pipeline (by ISS or OWIN).  This restricts the API to only authenticate using bearer tokens.
            config.SuppressDefaultHostAuthentication();

            // Enable authentication using bearer tokens
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Custom route constraints
            var constraintResolver = new DefaultInlineConstraintResolver();
            constraintResolver.ConstraintMap.Add("deviceState", typeof(DeviceStateRouteConstraint));
            constraintResolver.ConstraintMap.Add("companyId", typeof(CompanyIdRouteConstraint));
            constraintResolver.ConstraintMap.Add("macAddress", typeof(MacAddressRouteConstraint));

            // API attribute routing
            config.MapHttpAttributeRoutes(constraintResolver);

            // API action filters
            config.Filters.Add(new LogAttribute("PortalApi", 200));
            config.Filters.Add(new ValidateModelStateAttribute());
            config.Filters.Add(new GlobalExceptionFilterAttribute(logger));

            // API formatters
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter());

            logger.LogInfo(MethodBase.GetCurrentMethod(), "Web Api configuration complete.");
        }
开发者ID:hendrikdelarey,项目名称:appcampus,代码行数:44,代码来源:WebApiConfig.cs


注:本文中的Resolver.RegisterTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。