Looking at a lot of MVC source code, I notice that most MVC projects (especially larger projects) implement dependency injection in one way or another. I have two questions. First of all, is it feasible to create a large project without using dependency injection? I understand dependency injection makes large projects a lot easier to maintain and unit test. But how much more complex would a
看看很多MVC源代码,我注意到大多数MVC项目(尤其是大型项目)都以某种方式实现了依赖注入。 我有两个问题。 首先,不使用依赖注入来创建大型项目是否可行? 我了解依赖注入使大型项目更容易维护和单元测试。 但是一个没有使用依赖注入的项目会多复杂多少? 其次,在确定新项目的要求时,我应该使用什么标准来确定是否应该使用依赖注入? 它需要很多初始设置,有时对于一个简单的程序来说似乎没有必要。 没有像错误或
What alternative can one use to avoid exposing both events and an interface. I have a class that has a determined life cycle: created, modified, ... clients mainly GUIs need to hook up into the life cycle of that class so the simplest way to do it is to expose events, at the same time I need to move some responsibilities -that happen during the life cycle- out of the class so I came up with this
用什么替代方法可以避免暴露事件和界面。 我有一个具有确定生命周期的类:创建,修改,...客户端主要是GUIs需要连接到该类的生命周期,所以最简单的方法是公开事件,同时我需要在生命周期中将某些职责转移到课堂外,所以我想出了这个解决方案: Interface ILifeCycle { void OnCreated(...); void OnModified(...); // ... } classA { private ILifeCycle lifeCycle; /// ... public event EventHandl
I have an application using raw MVVM (without a framework). My ViewModels are a list that the MainViewModel manages, but there are some view models that need specific information (like user account, name etc...) that I get from a web service, so I've created a service that does this for me, I get the user account, username and other stuff and since my view models need this information I'
我有一个应用程序使用原始MVVM(没有框架)。 我的ViewModels是MainViewModel管理的列表,但是有一些视图模型需要从Web服务获得的特定信息(如用户帐户,名称等),所以我创建了一个服务来完成此操作我得到了用户帐户,用户名和其他东西,因为我的视图模型需要这些信息,所以我创建了一个工厂,返回ViewModels对象并将其插入到MainViewModel保存的集合中,并在构造函数中将该服务作为一个界面。 例: SelectionViewModel.cs
I have a interface called iChannels, which has only one method. using CHNL; namespace iInterface { public interface iChannels { string getData(string docXML); } } Then in another project I have a class called Channel1, wich is defined like this: using iInterface; namespace CHNL { public class Channel1:iChannels { string getData(string str) { r
我有一个名为iChannels的接口,它只有一个方法。 using CHNL; namespace iInterface { public interface iChannels { string getData(string docXML); } } 然后在另一个项目中,我有一个名为Channel1的类,这个类定义如下: using iInterface; namespace CHNL { public class Channel1:iChannels { string getData(string str) { return str; } } } 我不得不
In there any value in using IoC resolvable interfaces to specify DTOs? Fer example: private readonly IGetTransactionsQuery _query; private readonly ICreateTransactionCommand _createCommand; public TransactionsController( IGetTransactionsQuery query, ICreateTransactionCommand createCommand) { _query = query; _createCommand = createCommand; } [EnableQuery] public IQueryable<
在使用IoC可解析接口来指定DTO方面有什么价值? Fer例子: private readonly IGetTransactionsQuery _query; private readonly ICreateTransactionCommand _createCommand; public TransactionsController( IGetTransactionsQuery query, ICreateTransactionCommand createCommand) { _query = query; _createCommand = createCommand; } [EnableQuery] public IQueryable<ITransactionQueryModel> Ge
I have the following method: Void UpdateUser(User user){} I need to check this method whether will work properly. I've used a separate db to check this in unit testing. But many experienced people said if I use this method that won't be unit testing; that's integration testing. But I don't know how to mock for unit testing. The code written in the UpdateUser method, will
我有以下方法: Void UpdateUser(User user){} 我需要检查这种方法是否会正常工作。 我用单独的数据库在单元测试中检查了这一点。 但是很多有经验的人说如果我用这种方法不是单元测试的话; 这就是集成测试。 但我不知道如何模拟单元测试。 在UpdateUser方法中编写的代码将尝试使用Entity框架更新数据。 如果我嘲笑(其实我也不怎么这样做),这将如何与实体框架一起工作? 模拟意味着你开发软件组件(类)的方式是
I'm trying to set the variable DB as global and use anywhere. My problem is that I'm initialising twice the db. In the base controller and in atributes. ie: public class SettingsAttribute : ActionFilterAttribute { public ApplicationDbContext db = new ApplicationDbContext(); public override void OnActionExecuting(ActionExecutingContext filterContext) { ... } and [Settings] pu
我试图将变量DB设置为全局并在任何地方使用。 我的问题是我正在初始化数据库的两倍。 在基础控制器和属性中。 即: public class SettingsAttribute : ActionFilterAttribute { public ApplicationDbContext db = new ApplicationDbContext(); public override void OnActionExecuting(ActionExecutingContext filterContext) { ... } 和 [Settings] public class BaseController : Controller { public Applicat
Current application was developed by other developer by Dependency Injection using Unity. The application was developed in MVC4 and Entity Framework. This application is not big, not even medium sized application. Now, team wants to remove dependency injection as it is consuming lot of memory. My questions are 1) Is dependency injection really consume lot of memory ? 2) Advantages of ha
目前的应用程序是由其他开发人员通过依赖注入使用Unity开发的。 该应用程序是在MVC4和Entity Framework中开发的。 这个应用程序并不大,甚至没有中型应用程序。 现在,团队希望移除依赖注入,因为它消耗大量内存。 我的问题是 1)依赖注入是否真的消耗大量内存? 2)依赖注入的优点? 3)进行Unity,依赖注入的目的是什么? 4)如何从应用程序中删除此依赖注入? 谢谢 1)依赖注入是否真的消耗大量内存? 依
I've an object like this: public class Parents { public List<Parent> {get; set;} } public class Parent { public string name {get; set;} public int age {get; set;} public List<Child> {get; set;} } public class Child { public string name {get; set;} public int age {get; set;} } after filling "Parents" with multiple "Parent" and each of t
我有这样一个对象: public class Parents { public List<Parent> {get; set;} } public class Parent { public string name {get; set;} public int age {get; set;} public List<Child> {get; set;} } public class Child { public string name {get; set;} public int age {get; set;} } 在用多个“Parent”填充“Parents”并且每个都有一个来自xml的多个“Child”之后,我想让它们持久化(
I was looking at a project and I found something very curious. There is a static class that has a set of methods, where each method makes a call to a remote server. The template looks kind of like this: public static class DAI public static ResponseObject ExecStatement(string db, string sql) { { ... } } public static DataSetResponseObject GetDataSet(string db, stri
我正在看一个项目,我发现一些很好奇的东西。 有一个静态类有一组方法,其中每个方法调用远程服务器。 该模板看起来像这样: public static class DAI public static ResponseObject ExecStatement(string db, string sql) { { ... } } public static DataSetResponseObject GetDataSet(string db, string sql) { { ... } } public static DataTableResponseObject GetD