本文整理汇总了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));
}
示例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.");
}