inversion-of-control

Can you inject dependencies into a constructor of a custom WebViewPage, using an IOC container?

心已入冬 提交于 2019-12-19 02:49:20
问题 In MVC 3, I understand you can create custom WebViewPages. Can you inject dependencies, using constructor injection, via an IOC container? 回答1: There is an expample for view injection in a blog post by Brad Wilson http://bradwilson.typepad.com/blog/2010/07/service-location-pt3-views.html The statements of the others that views allow constructor injection not entirely correct. Yes IDependencyResolver enables creating views that have constructor arguments. But unless you are implementing your

What is the proper way to inject a data access dependency for lazy loading?

让人想犯罪 __ 提交于 2019-12-18 21:16:05
问题 What is the proper way to inject a data access dependency when I do lazy loading? For example I have the following class structure class CustomerDao : ICustomerDao public Customer GetById(int id) {...} class Transaction { int customer_id; //Transaction always knows this value Customer _customer = null; ICustomerDao _customer_dao; Customer GetCustomer() { if(_customer == null) _customer = _customer_dao.GetById(_customer_id); return _customer } How do I get the reference to _customer_dao into

What is the best way of using NLog with MEF?

旧时模样 提交于 2019-12-18 16:59:14
问题 I am wondering what is the best way to use NLog with Managed Extensibility Framework (MEF)? I have an application that support plugins using MEF architecture (Import and Exports etc) I want to add logging capability to my application. As a logging component I want to use NLog. What would you recommend? 1. Create a wrapper for NLog, i.e. additional plugin that configures NLog and exports functions like void Log(string level, string message) that other plugins importing 2. Every plugin should

Windsor Container: How to specify a public property should not be filled by the container?

馋奶兔 提交于 2019-12-18 14:58:09
问题 When Instantiating a class, Windsor by default treats all public properties of the class as optional dependencies and tries to satisfy them. In my case, this creates a rather complicated circular dependency which causes my application to hang. How can I explicitly tell Castle Windsor that it should not be trying to satisfy a public property? I assume there must be an attribute to that extent. I can't find it however so please let me know the appropriate namespace/assembly. If there is any way

Spring autowire and prototype scope

偶尔善良 提交于 2019-12-18 14:48:47
问题 I have a class named Bar with the following annotation: @Configurable(autowire = Autowire.BY_TYPE) On a private member I have the following annotation: @Autowired(required = true) private Foo foo; In the spring configuration I have a bean of class Foo. If the bean is defined with scope="prototype" it doesn't work and I get the following exception: NoSuchBeanDefinitionException: No matching bean of type Foo found for dependency: expected at least 1 bean which qualifies as autowire candidate

ASP.NET MVC + fluent nNibernate, what IoC tool?

三世轮回 提交于 2019-12-18 13:17:43
问题 I'm working on a ASP.NET MVC project where we have decided to use Fluent nHibernate for dataccess. To enable loose coupling we go for a IoC/DI pattern. My questions is what IoC tool to go for. I've tried to find the differences between windsor, ninject, spring, structuremap and unity, but it's difficult to see the benefits each one has to offer. Whats your experience? 回答1: I use StructureMap and it's very easy to use. Personally I don't like to configure using xml and StructureMap makes it a

Service Locator, Dependency Injection (and Container) and Inversion of Control

主宰稳场 提交于 2019-12-18 13:01:39
问题 I've been programming for some time but never got interested in knowing in theory what each concept means, I may be using a variety of programming concepts, but without knowing it. Service Locator : For me, refers to a record of shortcuts to speed up development by reducing the amount of code. One question is: may Locator refer to namespaces/classes only, or I can have a registry of variables? Here is my understanding of it: $locator = new ServiceLocator() $locator->set('app', new System

MEF = may experience frustration?

▼魔方 西西 提交于 2019-12-18 12:36:57
问题 UPDATE As I've tried to get MEF working throughout my application, I'm coming across more an more places where I just don't get why it's not automatically creating my library when I expect it to. I think it all comes back to what Reed was saying about needing MEF to create everything. So right now, I have an XML reader class that needs to use my CandySettings, but even though its ICandySettings property has the [Import] attribute, it doesn't get imported. First I found out that [Import] doesn

IoC, AOP and more

本秂侑毒 提交于 2019-12-18 11:58:01
问题 What is an IoC container? What is an IoC/DI framework? Why do we need a framework for IoC/DI? Is there any relationship between IoC/DI and AOP? What is Spring.net/ninject with respect to IoC and AOP? 回答1: JMSA, James Kovacs wrote a fantastic article which covers many of your questions I would recommend reading it Here Spring.Net, Ninject, Unity, Castle Windsor, Autofac are all IOC containers which are configurable in different ways, many of them do also support AOP. Frameworks for IOC/DI are

Where & How Castle Windsor sets up logging facility

筅森魡賤 提交于 2019-12-18 11:13:49
问题 I'm fairly new to Castle Windsor and am looking into the in's and out's of the logging facility. It seems fairly impressive but the only thing i can't work out is where Windsor sets the Logger property on my classes. As in the following code will set Logger to the nullLogger if the class hasn't been setup yet but when Resolve is finished running the Logger property is set. private ILogger logger; public ILogger Logger { get { if (logger == null) logger = NullLogger.Instance; return logger; }