inversion-of-control

StructureMap CacheBy InstanceScope.HttpSession not working

This is my StructureMap bootstrapping: ObjectFactory.Initialize(factory => { //Business Conversation is per session factory.ForRequestedType<IConversation>(). TheDefaultIsConcreteType<Conversation>(). CacheBy(InstanceScope.HttpSession); //Session Factory is life time factory.ForRequestedType<INHibernateSessionManager>...

What are some of the things to watch for (pitfalls) while using IOC container?

What are some of the things to watch for (pitfalls) while using IOC container? ...

good open source project using Dependency Injection Framework?

does anyone know about an open source project Implementing Ninject Framework or another one, I haven't work with a DI framework before and Ninject calls my attention because you don't need to have your configuration in XML files. i tend to grasp a lot more when reviewing already implemented code. also if you know about another good p...

How do I use IoC in a setup like this? Is there a better way to test this?

I'm building a blog engine to test some concepts such us TDD and using inversion of control... I came up with a setup where I'd have a generic IBlogRepository interface so I could support both SQL and XML. public interface IBlogRepository : IRepository { Post GetPostById(Guid postId); Post GetPostByFriendlyUrl(string friendlyUrl); L...

Spring IoC and Generic Interface Type

Hi all, I'm trying to use Spring IoC with an interface like this: public interface ISimpleService<T> { void someOp(T t); T otherOp(); } Can Spring provide IoC based on the generic type argument T? I mean, something like this: public class SpringIocTest { @Autowired ISimpleService<Long> longSvc; @Autowired I...

StructureMap InstanceScope.Hybrid and IDisposable

I'm working on an asp.net-mvc application. The linq data context is being passed into my service objects by structure map. I've got is set to have a scope of hybrid. This all works just fine. protected override void configure() { ForRequestedType<AetherDataContext>() .TheDefaultIs(() => new AetherDataContext()) .CacheBy(Instan...

Why would you want Dependency Injection without configuration?

After reading the nice answers in this question, I watched the screencasts by Justin Etheredge. It all seems very nice, with a minimum of setup you get DI right from your code. Now the question that creeps up to me is: why would you want to use a DI framework that doesn't use configuration files? Isn't that the whole point of using a DI...

What are the pros and cons for using a IOC container?

Using a IOC container will decrease the speed of your application because most of them uses reflection under the hood. They also can make your code more difficult to understand(?). On the bright side; they help you create more loosely coupled applications and makes unit testing easier. Are there other pros and cons for using/not using a ...

Setter / property injection in Unity without attributes

I am working on a project where the Unity framework is used as the IoC container. My question relates to injecting an optional dependency (in this case a logger) into several classes using property- or setter injection. I do not want to clutter the constructors of all my classes with these optional dependencies, but I cannot find a goo...

IoC and events

I am having a really hard time reconciling IoC, interfaces, and events. Let's see if I can explain this without writing a book. I'm just getting started with IoC and I'm playing with Spring. We have a simple data layer that was built long before EF or the others. One of the classes is a DBProcedure which has some methods and events. I ...

How should I design a class library to allow for IoC, but not depend on a particular container

I'm developing a class library that will be used in a number of different web applications, and possibly even made available as an open source project. There are several points where I would like to use IoC, but I don't want consumers of the class library to have to use one particular implementation. What is the best way to design this...

Is there a commonly used OO Pattern for holding "constant variables"?

I am working on a little pinball-game project for a hobby and am looking for a pattern to encapsulate constant variables. I have a model, within which there are values which will be constant over the life of that model e.g. maximum speed/maximum gravity etc. Throughout the GUI and other areas these values are required in order to correc...

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

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 t...

Windsor IoC Sample Help - "HttpServiceWatcher& which was not registered."

I'm following the Windsor Inversion of Control (IoC) Getting Started example, which is in C#, but I'm implementing it in VB.Net, and I've run into a small problem.. Here's the exception I'm getting in full: Can't create component 'form.component' as it has dependencies to be satisfied. form.component is waiting for the following ...

What is the relationship between "late binding" and "inversion of control"?

In his definition of OOP, Alan Kay points out he supports "the extreme late-binding of all things". Does his interest in late-binding share the same motivation as people's interest in IoC? In particular, would it be correct to say that both are motivated by the concept "specify as little as possible, and leave implementation details to ...

Ninject : Resolving an object by type _and_ registration name/identifier

I am looking for a way to do something like this with Ninject : // Sample from the Unity application block IMyService result = myContainer.Resolve<IMyService>("Data"); ( from http://msdn.microsoft.com/en-us/library/cc440957.aspx ) Is it possible? ...

Ninject OnePerRequestBehaviour doesn't seem to work correctly?

I've been using Ninject as my IOC in my web app. It's great and I think it works really well, however I have been trying to register some interfaces / classes as OnePerRequestBehaviour but it doesn't seem to actually use the behaviour. The code runs correctly but in one of my classes it lazy loads page information from the database then ...

Instantiate A Class For Testing

I need to test a method belonging to a service class. This service class has several dependencies in the constructor, some used by this method, some not. If we should not be using a DI container for our unit tests what is the best way to instantiate the service class? var service = new ServiceClass(new Repository1(), new Repository2()...

Null Inner Bean with Spring IoC

Hi all. I have a singleton bean definition like this: <bean id="exampleBean" class="com.examples.ExampleBean"> <property name="exampleBean2"> <bean class="com.examples.ExampleBean2" /> </property> </bean> where ExampleBean could be: public class ExampleBean { private ExampleBean2 exampleBean2; public ExampleBean() { } ...

Can Guice initialize beans?

I've used Spring before (and like it), but thought I'd take a look at Guice. Is there a way to initialize something like maps or lists into beans using Guice? For instance, I've done the following before in Spring to inject a list of items I want to process into some bean. <property name="FilesToProcess"> <list> <value>file1....