草庐IT

add_runtime_dependency

全部标签

c# - DI Framework : how to avoid continually passing injected dependencies up the chain, 且未使用服务定位器(特别是使用 Ninject)

我需要更多帮助才能“了解”像Ninject这样的DI框架如何超越基础知识。以Ninject为例:classSamurai{privateIWeapon_weapon;[Inject]publicSamurai(IWeaponweapon){_weapon=weapon;}publicvoidAttack(stringtarget){_weapon.Hit(target);}}如果没有DI框架(即上面的[Inject]引用),引用类将类似于:classProgram{publicstaticvoidMain(){Samuraiwarrior1=newSamurai(newShuriken

c# - ASP.NET Core RC2 项目引用 "The Dependency X could not be resolved"

概览我有一个ASP.NETCoreRC2.NET框架Web项目,我想添加对同一解决方案中包含的常规C#类库的项目引用。重现步骤:使用VisualStudio2015更新2文件->新建项目->ASP.NETCoreWeb应用程序(.NETFramework)右键解决方案->新建项目->类库我不会做这些:类库(.NETCore)类库(适用于iOS、Android和Windows)类库(可移植)将以下内容添加到project.json中的dependencies中:"ClassLibrary1":{"version":"*","target":"project"}问题为什么在指定项目依赖项时

c# - 为什么 DbSet Add 返回的是实体实例而不是 void?

DbSet.Add方法返回一个实体。我通常会期待Add操作有void返回类型。当我查看EntityFrameworksourcecode,我看到了以下实现:publicvirtualTEntityAdd(TEntityentity){Check.NotNull(entity,"entity");GetInternalSetWithCheck("Add").Add(entity);returnentity;}GetInternalSetWithCheck返回InternalSetAddInternalSet的方法|有趣的是,它的签名中有一个void返回类型:publicvirtualvo

c# - 在 c# Parallel.ForEach 中的 List.Add() 上出现 "Index out of bounds"错误

这是代码Listsomething=newList();Parallel.ForEach(anotherList,r=>{..dosomeworksomething.Add(somedata);});Indexoutofbounds错误大约每百次运行1次。有没有办法防止由线程引起的冲突(我假设)? 最佳答案 为了防止出现此问题,您可以使用ConcurrentQueue而不是List或并行部分中的类似并发集合。并行任务完成后,您可以将其放入List中。.有关详细信息,请查看System.Collections.Concurrent命名

c# - 无法加载文件或程序集 ':This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded

我在我的解决方案中有3个项目:BL、DL和UI。这三个项目的目标框架都是>NET4;我通过查看每个项目的属性页仔细检查了这一点。当我尝试在托管环境中运行网站时收到以下错误消息,但在本地运行时却没有。Couldnotloadfileorassembly'BL'oroneofitsdependencies.Thisassemblyisbuiltbyaruntimenewerthanthecurrentlyloadedruntimeandcannotbeloaded.提前致谢! 最佳答案 -转到IIS。-DefaultWebSite->Y

c# - Microsoft Visual Studio 和 C# : How to Visually Add Events to Controls?

如何使用C#在MicrosoftVisualStudio(2008)中的表单中向控件添加事件处理程序?我可以手动完成,但是打开Form的Designer.cs文件,但我找不到通过界面完成的方法。在MSVC6中,使用C++和MFC,您可以右键单击或其他一些操作,并找到该控件所有可能事件的列表。然后你选择它,它会弹出窗口让你创建一个方法来关联那个事件。在VB中更容易,您可以在代码中完成,它会在方法下拉列表中列出所有事件。但是,我无法在2008年使用C#找到任何此类内容。Intellisense帮助填写正确的方法信息。但是,它总是在Designer.cs文件中创建方法,而不是在分部类的另一半

c# - 生产中的 Azure SDK 2.2 : Could not load file or assembly 'msshrtmi' or one of its dependencies. 系统找不到指定的文件

我已经在StackOverflow和其他网站的其他几个线程上读到过这个问题。其他解决方案都没有解决我的问题,而且大多数都已过时,引用了旧版本的AzureSDK。我有一个典型的Azure网站角色部署到Azure,它使用Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener来记录跟踪消息。发生跟踪时,看起来好像DiagnosticMonitorTraceListener正在使用RoleEnvironment类,该类又会尝试加载显然不存在的msshrtmi.dll.这是记录到Azure文件系统的堆栈跟踪的一部分:[F

c# - 带有 Attach() 的 LINQ To SQL 异常 : Cannot add an entity with a key that is already in use

考虑这个典型的断开连接的场景:使用LINQToSQL从SQLServer加载客户对象用户编辑实体,表示层发回修改后的实体。数据层,使用L2S,必须将更改发送到SQLServer考虑这个LINQToSQL查询,其目的是获取客户实体。CustcustOrig=db.Custs.SingleOrDefault(o=>o.ID==c.ID);//gettheoriginaldb.Custs.Attach(c,custOrig);//wedon'thaveaTimeStamp=Truepropertydb.SubmitChanges();DuplicateKeyException:Cannota

c# - IDbSet.Add 和 DbEntityEntry.State = EntityState.Added 有什么区别?

在EF4.1+中,这两行代码之间有区别吗?dbContext.SomeEntitySet.Add(entityInstance);dbContext.Entry(entityInstance).State=EntityState.Added;或者他们做同样的事情?我想知道一个是否会以不同于另一个的方式影响子集合/导航属性。 最佳答案 当您使用dbContext.SomeEntitySet.Add(entityInstance);时,此及其所有相关实体/集合的状态设置为已添加,而dbContext.Entry(entityInstan

c# - EF4 代码优先 : how to add a relationship without adding a navigation property

我应该如何在不使用任何导航属性的情况下使用CodeFirst来定义关系?之前,我通过在关系的两端使用导航属性来定义一对多和多对多。并在数据库中创建适当的关系。这是类外观的精简版本(为简单起见,我已将多对多关系转换为一对多)。publicclassUser{publicstringUserId{get;set;}publicstringPasswordHash{get;set;}publicboolIsDisabled{get;set;}publicDateTimeAccessExpiryDate{get;set;}publicboolMustChangePassword{get;set