我正尝试使用OWIN通过以下链接自我填充Web API
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api
但是,在执行以下行
期间using (WebApp.Start<SelfHostStartup>(url: baseAddress))
我收到 EntryPointNotFoundException ,因为在程序集中找不到MyNamespace.SelfHostStartup。
任何帮助将不胜感激。
谢谢。
public class SelfHostStartup
{
// This code configures Web API. The Startup class is specified as a type
// parameter in the WebApp.Start method.
public void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
var config = new HttpConfiguration();
// Loads external library's (that contain the web api controllers) into the web api self host system
var assemblyResolver = new SelfHostAssemblyResolver();
config.Services.Replace(typeof(IAssembliesResolver), assemblyResolver);
// Creates the IoC Container & mounts to Web API
config.DependencyResolver =
new AutofacWebApiDependencyResolver(Framework.Infastructure.Dependency.AutofacContainer.Container);
config.Services.Add(typeof(IExceptionLogger), new MyNamespace.ApiExceptionLogger(Framework.Infastructure.Dependency.AutofacContainer.Resolve<ILogger>()));
// Configures Web API Controller Routing
RouteConfig(config);
config.EnsureInitialized();
// Tells OWIN self host to use this configuration
appBuilder.UseWebApi(config);
}
/// <summary>
/// Configuration of the Routing for the Web API Controllers
/// </summary>
/// <param name="config"></param>
private void RouteConfig(HttpConfiguration config)
{
#if DEBUG
//Enabling Cors Globally
config.EnableCors(new EnableCorsAttribute("http://localhost:60279", "*", "*"));
#else
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
#endif
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "Core",
routeTemplate: "api/core/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "Domain",
routeTemplate: "api/domain/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "Domain1",
routeTemplate: "api/domain/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}