C# Difference between factory pattern and IoC

Possible Duplicate: Dependency Injection vs Factory Pattern Can someone please explain (with SIMPLE examples) of the difference between the factory pattern and Inversion of Control pattern. Preferably using .NET2.0 The factory pattern: the object which needs a reference to a service, should know about the factory that creates the Service: public class BLLObject { public IDal DalInsta

C#工厂模式和IoC之间的区别

可能重复: 依赖注入vs工厂模式 有人可以解释(用简单的例子)工厂模式和控制反转模式之间的区别。 最好使用.NET2.0 工厂模式:需要引用服务的对象,应该知道创建服务的工厂: public class BLLObject { public IDal DalInstance { get; set; } public BLLObject() { DalInstance = DalFactory.CreateSqlServerDal(); } } Ioc模式(或依赖注入): 该对象只需要使用Ioc模式的任何方面(构

The username is not provided. Specify username in ClientCredentials

I Create a WCF application with client credential. It's working fine internally while i refer and call this service from the other project means i got the error message. The username is not provided. Specify username in ClientCredentials. Please help me to solve this. <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IWcfService" closeTimeout="00:01:00"

没有提供用户名。 在ClientCredentials中指定用户名

我使用客户端凭证创建一个WCF应用程序。 它在内部工作正常,而我从另一个项目中引用并调用此服务意味着我收到了错误消息。 The username is not provided. Specify username in ClientCredentials. 请帮我解决这个问题。 <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IWcfService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="0

Service locator and dependency injection

I think it's universally agreed that following is bad public class Foo { private IService _service; public Foo() { _service = IocContainer.Resolve<IService>(); } } and that following is preferred (Dependency Injection) public class Foo { private IService _service; public Foo(IService service) { } } However now it's up to the consumer to pr

服务定位器和依赖注入

我认为普遍认为以下是不好的 public class Foo { private IService _service; public Foo() { _service = IocContainer.Resolve<IService>(); } } 并且以下是优选的(依赖注入) public class Foo { private IService _service; public Foo(IService service) { } } 但是,现在取决于消费者提供服务。 消费者当然也可以在构造函数中要求IService,但是当层次结构变得更深时

Dependency injection and named loggers

I am interested in learning more about how people inject logging with dependency injection platforms. Although the links below and my examples refer to log4net and Unity, I am not necessarily going to use either of those. For dependency injection/IOC, I will probably use MEF as that is the standard that the rest of the project (large) is settling on. I am very new to dependency injection/ioc

依赖注入和命名记录器

我有兴趣进一步了解人们如何使用依赖注入平台注入日志。 虽然下面的链接和我的示例都提到了log4net和Unity,但我不一定会使用其中的任何一个。 对于依赖注入/ IOC,我可能会使用MEF,因为这是项目其他部分(大)正在解决的标准。 我对依赖注入/ ioc非常陌生,并且对C#和.NET来说很新颖(在VC6和VB6的过去10多年中,在C#/ .NET中已经编写了很少的生产代码)。 我已经对各种各样的日志解决方案进行了很多调查,所以我认为我

DacPac exclude users and logins on export or import

Im doing some automation and in the middle of rewriting some 10-15 old, quirky scripts to one single and simple unit, which can: Export a database scheme from MsSql2012 in production environment Import the database scheme to MsSql2012 in development environment Im doing this using the Microsoft.SqlServer.Dac in which i can export/import dac packs. It works nicely :), but after doing all m

DacPac排除用户并登录导出或导入

我正在做一些自动化操作,并正在将一些10-15岁的古怪脚本重写为一个简单的单元,这可以: 在生产环境中从MsSql2012导出数据库方案 在开发环境中将数据库方案导入MsSql2012 我使用Microsoft.SqlServer.Dac来完成这项工作,我可以在其中导出/导入dac包。 它很好地工作:),但是在完成我的所有TDD和测试之后,现在是真正的时间了,事实证明我完全错过了我们的工作中有两个域。 这意味着当我在开发环境中导入dacpac时会出现

Why isn't my for loop printing like I would expect from my pseudocode?

int main(void) { int height = 24; while (height > 23 || height <=0) { printf("How tall do you want the tower to be?n"); height = GetInt(); } for(int a = 0; a < height; a++) { for(int c = a; c<=height; c++) { printf(" "); } for(int b = height - a; b<=height; b++) { printf("#"); } printf("n"); } } So, what I'm trying to do is have a t

为什么我的循环打印不像我期望从伪代码那样?

int main(void) { int height = 24; while (height > 23 || height <=0) { printf("How tall do you want the tower to be?n"); height = GetInt(); } for(int a = 0; a < height; a++) { for(int c = a; c<=height; c++) { printf(" "); } for(int b = height - a; b<=height; b++) { printf("#"); } printf("n"); } } 所以,我试图做的是有一个塔与终端窗口的左

Adding UIWebView inside UIScrollView XAMARIN.IOS C#

I'd like to add a UIWebView (and some other elements) in a UIScrollView. First of all, my UIWebView has not a fix text and could be change. So, as I saw in examples and tutorials I can do it like this: public class testArticleViewController : UIViewController { private UIScrollView _scrollView; //Post elements UIWebView _artcileTextWeb; public testAr

在UIScrollView中添加UIWebView XAMARIN.IOS C#

我想在UIScrollView中添加一个UIWebView(和其他一些元素)。 首先,我的UIWebView没有修复文本,可以更改。 所以,正如我在例子和教程中看到的,我可以这样做: public class testArticleViewController : UIViewController { private UIScrollView _scrollView; //Post elements UIWebView _artcileTextWeb; public testArticleViewController() { Title = "te

Inject debug information into Entity Framework queries

We're using Dapper and EF in our shop, and Dapper proofed to be extremely helpful in debugging queries in SQL server when something went wrong. Instead of just submitting raw SQL, we created a thin decorator that also adds some context information (the origin) as an SQL comment, something like /* Foo.Bar.GetOrders() */ SELECT * FROM Order WHERE orderId > 123 This allows our DBAs and dev

将调试信息注入实体框架查询

我们在我们的商店中使用Dapper和EF,并且Dapper证明在出现问题时调试SQL Server中的查询非常有帮助。 我们不是只提交原始SQL,而是创建了一个精简的装饰器,它还将一些上下文信息(来源)添加为SQL注释,类似于 /* Foo.Bar.GetOrders() */ SELECT * FROM Order WHERE orderId > 123 这使我们的DBA和开发人员能够非常快速地进行响应,并且如果我们有错误的DB调用或引入性能命中(我们每天有数十万个数据库调用,所以一个错

Maximum number of elements in an array vs. maximum indexer value

today I started wondering about something in the MSDN. This article demonstrates, how one can increase the memory allocatable by an array under .NET 4.5 and x64. This is a nice feature, but something in the description provided by Microsoft baffeles me. Under the section "Remarks" they say, that: The maximum index in any single dimension is 2,147,483,591 (0x7FFFFFC7) for byte arra

数组中元素的最大数量与最大索引器值

今天我开始想知道MSDN中的一些东西。 本文演示如何通过.NET 4.5和x64下的数组增加可分配的内存。 这是一个很好的功能,但是Microsoft提供的描述中的某些内容对我很有帮助。 他们说,在“备注”一节中说: 对于其他类型的字节数组和单字节结构数组,在任何单维中的最大索引为2,147,483,591(0x7FFFFFC7),对于其他类型,则为2,146,435,071(0X7FEFFFFF)。 由于我主要有int[]或double[]所以后一个数字与我的索引相关。 我

How to make (1 << 9) pass MISRA?

This question already has an answer here: MISRA C:2004, error with bit shifting 2 answers 你也可以简单地通过使用来规避移位问题 #define MOTOR_ON ((uint16_t)512U) /* 1 << 9 = 2^9 */ My advice is to define a macro that hides the ugly casting, but then go ahead and do the ugly casting to make MISRA happy. Something like: #define LSHIFT(x, n) (((unsigned int)(x)) << ((unsigne

如何使(1 << 9)通过MISRA?

这个问题在这里已经有了答案: MISRA C:2004,错误与位移2答案 你也可以简单地通过使用来规避移位问题 #define MOTOR_ON ((uint16_t)512U) /* 1 << 9 = 2^9 */ 我的建议是定义一个隐藏丑陋演员的宏,但是继续做丑陋的演员让MISRA感到高兴。 就像是: #define LSHIFT(x, n) (((unsigned int)(x)) << ((unsigned int)(n))) 然后在你的实际代码中: #define MOTOR_ON LSHIFT(1, 9) 编辑:在下面的评