问题描述
我刚开始我的脚湿MVC 6.我安装了VS 2015年和默认 ASP.NET 5 preVIEW
MVC Web应用程序
模板一切运行在本地IIS罚款。
我然后试图用 StructureMap
转出默认的DI容器下面的准确(注意这是一个非常最近的一篇文章)。唯一的一点是我必须要弄清楚的命名空间来导入自己(因为笔者忘了把它们),这就是我在内。
我把 StructureMa pregistration
类和所有相关的类到一个文件,这里是usings。
使用Microsoft.Framework.DependencyInjection;
使用StructureMap;
使用StructureMap.Configuration.DSL.Ex pressions;
我添加了以下usings到 Startup.cs
文件。
使用StructureMap;
使用StructureMap.Graph;
使用的System.Reflection;
和我做了以下编辑到 Startup.cs
文件。
//此方法被运行时调用。使用此方法可以服务于容器中添加。
公共无效ConfigureServices(IServiceCollection服务)
{
//到服务容器添加实体框架服务。
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext< ApplicationDbContext>(选项=>
options.UseSqlServer(配置[数据:DefaultConnection:ConnectionString的])); //到服务容器添加身份服务。
services.AddIdentity< ApplicationUser,IdentityRole>()
.AddEntityFrameworkStores< ApplicationDbContext>()
.AddDefaultTokenProviders(); //配置认证中间件的选项。
//可以如下图所示谷歌,Twitter和其他中间件添加选项。
//欲了解更多信息,请参阅http://go.microsoft.com/fwlink/?LinkID=532715
services.Configure< FacebookAuthenticationOptions>(选项=>
{
options.AppId =配置[认证:Facebook的:的AppId];
options.AppSecret =配置[认证:Facebook的:AppSecret];
}); services.Configure< MicrosoftAccountAuthenticationOptions>(选项=>
{
options.ClientId =配置[验证:MicrosoftAccount:客户端Id];
options.ClientSecret =配置[验证:MicrosoftAccount:ClientSecret];
}); //到服务容器添加MVC服务。
services.AddMvc(); ////取消对以下行添加的Web API服务,这使得它更容易端口的Web API 2控制器。
////你还需要将Microsoft.AspNet.Mvc.WebApiCompatShim包添加到project.json的依存关系部分。
//// services.AddWebApiConventions(); ////注册应用服务。
//services.AddTransient<IEmailSender,AuthMessageSender&GT;();
//services.AddTransient<ISmsSender,AuthMessageSender&GT;(); VAR集装箱=新容器();
container.Configure(X =&GT;
{
x.Scan(扫描=&GT;
{
scanning.Assembly(Assembly.GetExecutingAssembly());
scanning.TheCallingAssembly();
scanning.WithDefaultConventions();
}); //x.AddRegistry<WebsiteRegistry>();
}); //我们的框架扩展点
container.Populate(服务);
}
The using statements suppress all of the design time compilation errors, but when I build, I get several other errors.
The error indicates where the problem is - I need a reference to mscorlib 2.0.5.0. But I am already referencing mscorlib 4.0.0.0 in the project.
At this point in ASP.NET < 5, the next step would typically be to add some binding redirects to the <bindingRedirect>
section of the web.config file. However, after searching for how to do this in ASP.NET 5, I came across this answer which indicates that binding redirection is supposed to be "totally automatic".
So is this a bug, or is there some step in my configuration that I missed that is resulting in this error?
Configuration
project.json
{
"webroot": "wwwroot",
"userSecretsId": "aspnet5-TestDI3-1665343b-5aa5-4d08-8596-a1a536223a19",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.SqlServer": "7.0.0-beta5",
"EntityFramework.Commands": "7.0.0-beta5",
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta5",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5",
"Microsoft.Framework.Logging": "1.0.0-beta5",
"Microsoft.Framework.Logging.Console": "1.0.0-beta5",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta5",
"structuremap": "3.1.6.186"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}
Thanks to opiants, the problem appears to be related to the fact that the dnxcore50
framework was included in the project.
"frameworks": {
"dnx451": { },
"dnxcore50": { }
}
Removing it solved the issue.
"frameworks": {
"dnx451": { }
}
这篇关于我该怎么办时,ASP.NET 5(vNext)不能重定向的绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!