dependency-injection

Resetting an IKernel in Ninject v1

I am experiencing an issue with v1 of Ninject and resetting the StandardKernel. I have a static object that I use to provide access to the kernel like so public static class ObjectFactory { private static IKernel _kernel = new StandardKernel(new CanceisModule()); // Resolve methods snipped for brevity public static void ...

Dependency Injection and .NET Attributes

I have a couple of method attributes which do some logging. Our logging code sits behind an interface (ILog) and I'd like it if the attributes were only dependent upon that interface as opposed to an implementation. This isn't really about testability or dependency inversion so much as it is about keeping the coupling of components clean...

Why is Castle Windsor trying to resolve my 'Content' and 'Scripts' folder as a controller??

I have created an ASP.NET MVC application and am trying to use Castle Windsor as my IOC However, when the controllers are trying to resolve I am getting 'Content' and 'Scripts' into the 'controllerName' parameter in the CreateController(RequestContext requestContext, string controllerName) method. Needless to say these are not controlle...

Is it bad to use servicelocation instead of constructor injection to avoid writing loads of factory classes

Right now we use DI/IOC and when we need to pass extra parameters to a constructor we use a factory class e.g. public class EmailSender { internal EmailSender(string toEmail, string subject,String body, ILogger emailLogger) {.....} } public class EmailSenderFactory { ILogger emailLogger; public EmailSenderFactory(ILog...

spring: set property of one bean by reading the property of another bean?

Is it possible to set the property of one bean by reading the property of another bean? For instance, suppose I had: class A { void setList(List list); } class B { List getList(); } I would like Spring to instantiate both classes, and call A's setList method, passing in the result of calling B's getList method. The Spring confi...

Best way to use an IoC container for retrieving runtime settings

I have an C# dll project for which I have to store the runtime settings in an external XML file, and this dll will be used in an ASP.NET/ASP.NET MVC application for which I also have to store the runtime settings in a external file. Which IoC container can be used to create an object with the runtime settings loaded from a specific exte...

StructureMap DI on Model Assembly

I’m new to Dependency Injection and had a question/need guidance. I had an application that used the repository pattern for data access. I used StructureMap to get the correct repository and all worked well. I have since broken out my model (including the repository logic) into its own assembly and added a service layer. In the interes...

Spring Philosophy

Everytime I ask anyone what is Spring Framework or what does it do ?, they simply say me, you remember that Hollywood Principle right "Don't Call me, I will Call you", that's exactly what Spring Framework does. What should I make out of this ? ...

ValidateInputAttribute not used in custom Controller Factory

I use the following Controller Factory with StructureMap: public class ShopControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(Type controllerType) { if (controllerType == null) throw new HttpException(404, "Controller Not found"); try { return ...

Typemock and Dependency Injection, still use interfaces?

Hi I see some good design benefits in DI and not just good testability design. So even though I have Typemock and could unit test without IOC, I still prefer constructor DI. I think it's a great way to quickly discover the dependencies of a class. Now I'm wondering should I keep using interfaces as the type parameter in the constructor...

Run Time Object Graph Builder Composition Library

I am working on a project and have started to use IOC/DI (Unity) and I've looked into MEF. I have come across something which is related to IOC/DI and could probably reuse many of the components that IOC/DI containers use but which isn't the same. This scenario is close to what MEF is trying to accomplish, but rather than assume that f...

MVC vs Dependency Injection

Can anyone summarize or bulleted list the types of things that go in each layer, and what layers are there in an MVC type design if you account for Dependency Injection? I haven't found any clean diagrams that help me figure out where or try to go more in detail without writing an entire book. I've been doing windows forms apps (inclu...

Repository pattern with Linq to SQL using IoC, Dependency Injection, Unit of Work

There seems to be lots of examples on implementing Repository pattern for Linq to SQL. Most of them featuring IRepository and DI; Some have implemented Unit of Work and some not. I tried to read as most of the results returned by searches on SO and Google on Linq to SQL repository patterns. Nevertheless I've not come across a complete so...

How can I use Windsor to inject a dependency into an ASP.NET MVC model?

I have a a model class that needs access to my repository class (used for DB access). I have created an interface for my repository and have successfully configured Castle Windsor to inject my the appropriate IRepository-based class into my controllers via a custom ControllerFactory. I'm having a little more trouble figuring out how to...

How do I use dependency injection with an ASP.NET MVC model?

I would like to inject a dependency into an ASP.NET MVC model, but I can't figure out where in the pipeline to do the injection. It's very straightforward with a ControllerFactory, but not nearly as much when dealing with models. ...

Unity in static methods

Hi, a possibly simple problem, but weird why I have no idea how to do it: Unity (PRISM) and static methods. In this special case, an extension method. But in general, how do I access a "unity provided instance" in a static method. Think e.g. of a logging service I want to access to log some stuff I am doing inside a static method. Do I...

Container Resolve based on criteria

I'm trying to implement the Strategy pattern while using Windsor container. Here is what I have: public class OrderProcessor { ... public OrderProcessor(ITaxStrategy strategy) {} public void Process(Order order) { order.Tax = strategy.CalcTax(order); } } The problem is, how do I configure my container (other c...

StructureMap - Insert Dependency upon Demand

Hi there, i'm trying to make my exceptionhandling dependend on the context. I have a factory class constructing exceptionhandlers. the handler should be constructed by the last thrown exception type. configuring structuremap the classic way, it works out fine. trying to use conditional constructing, my code fails and i can't see why?! W...

Having trouble with Dependency Injection and ASP.NET MVC

Hi folks, I've got a greedy constructor defined for my Controllers. Each controller requires an ILoggingService instance. Now my dependency injection (which is StructureMap .. but if you don't use that, please keep reading) works fine .. but I wish to make it that the ILoggingService greedy constructor requires a String. This value will...

How to explain Dependency Injection to a 5-year old

Hello there, Could anybody point out a good dependency injection tutorial? I found a ton on Google but none of them that would assume the reader is a just Java beginner. Thanks! ...