dependency-injection

Development and deployment - how to get service assemblies into their proper location?

Hi, This has to be a pretty common issue, and while we have answers, I'm trying to determine if there is any better way. We are using IoC / DI with structuremap. This means that our final application (an Asp.Net MVC 2 app) requires the presence of some assemblies which aren't being referenced anywhere else (our implemention of IReposi...

Should I register ViewModels in Container?

Should I register ViewModels in Container and resolve from there? Benefits: I can perform some actions when view model is activated Container will inject dependencies for me ??? Drawbacks: ViewModel lifetime management can be tricky: if I make ViewModel singleton then I can't instantiate several controls of the same type if I mak...

Dependency injection - need larger example?

Hi, i'm looking for a larger example of dependency injection and how it can be implemented. If class A depends on class B and passes a reference of class C to B's constructor, must not class A also take a reference to class C in it's constructor? This means that the main method in the application should create all classes really, which ...

The best way to import a collection of values in a controller using MEF

I have an ASP.NET MVC2 application that supports visualization plug-ins/providers. The IVisualization interface is defined in a common assembly which is referenced by both the ASP.NET MVC2 app, and any visualization providers. In the Visualization controller, I have a method which returns all the applicable visualizations for a given se...

Unity: Am example of a bootstrapper file?

Hi there, does anyone have a good example of a boostrapper class i can see for reference.. I can't seem to find one anywhere, searched google but no luck. Searched the helpfile and no luck.. Any help really appreciated ...

Unity: How to registerType with a PARAMETER constructor?

Hi there, Can anyone help? How do i registertype with the container where the type doesn't have NO PARAMETER constructor. Infact my constructor accepts a string .. and i normally pass in a string that represents a Path. So when i do resolve it automatically creates the new type but passing in a string? Thanks in advance ...

Grails Dependency Injection Problem

Hi, I am having problems when using dependency injection with Services in Grails. class ExampleService{ def example2Service def example3Service def method1(){ def result = example2Service.method2() } } class ExampleService{ def example3Service def method2(){ def result = example3Service.metho...

Add Factory Support for a Windsor Registration Dynamically

I have an interface public interface IResolver<T> { T Resolve(); } I know this isn't the ideal (service locator is an anti-pattern and all), but in some cases it's still necessary (for example WCF service activation - I don't want to instantiate the channel until Resolve() is explicitly called...and in the case of BasicHTTP, the ...

Castle Windsor Internal Constructor/Class

I looked at this and it answers half my questions: http://stackoverflow.com/questions/2370546/castle-windsor-register-class-with-internal-constructor But can you use Windsor to use internal constructors/class along with dependency injection? (so constructor parameters get injected too)? I'd like to keep the class/constructor internal t...

Windsor Registration Child Container Visibility

I have some (sort of) Singletons which exist in three context: Per AppDomain Per HttpApplication Per Web Request Right now, I'm creating a child container per HttpApplication and another child per Web Request. This is necessary because some components SHOULD actually share singleton instances across the three layers. For security and...

Guice wrap generic injections

Is it possible to wrap generic injections in some way? Given the interface: interface IFoo<T> In my guice module: bind((Key<IFoo<SomeType>) Key.get(Types.newParameterizedType(IFoo.class, SomeType.class))).to(Foo.class); But before I return the Foo instance I want to wrap it with this: class FooWrapper<T> implements IFoo<T> { public...

How to provide ASP.NET MVC2 master pages with a model indepdent of the controller

I'm using strongly typed views and autofac for Dependency Injection under ASP.NET MVC2 and I'm trying to get a common dynamic header via dependency injection. I.e. i want this to happen without the view having to be away of this content even existing and i was hoping to avoid static discovery of the container and manual resolution, but I...

Should I make concrete class dependencies explicit through constructor injection in my classes?

I am doing the design of a small project where I didn't use programming against interfaces for all my classes. I found that some classes would hardly ever be needed to change, so I let them be referenced by their client classes as concrete classes. So, let's say we have ClassB that'll be consumed be consumed by ClassA: class ClassB {...

.NET Reflective Dependency Injection with Multiple Containers

Hi Guys, I'm relatively new to dependency injection, so I'm probably butchering the concept to some extent. However, I'm trying to achieve something like the following, but am unsure as to whether or not it's feasible: Lets say I have two containers, each containing different instances of the same type of dependency. For example, each ...

how to access main class objects in other classes without a constructor in a processing/java eclipse project?

I cant seem to find an answer on the internet anywhere. So I have a processing project in Eclipse I want to be able to access objects in my "main" class that extends PApplet in another class without having to pass them through the constructor. I am not the most experienced programmer so my terminology might be off but hopefully this ex...

Cannot Inject EJB in GWT ServiceImpl (JBoss 4.2)

Hi Guyz, I am using Eclipse 3.6 and jboss 4.2 I've created Enterprise Application with two modules, EJB and WEB. I have converted the WEB module into GWT application (and added necessary files - html and css) The problem is, when I need to Inject either the Remote or Local interfaces in the GWTServiceImpl servlet using the @EJB annota...

Unity Dependency Injection using a config file - cant resolve dependency

Hi All, I'm using my app.config to tell Unity my interface to type mappings... <unity> <containers> <container> <types> <type type="UnityDAL.Interfaces.IDataContextFactory, UnityDAL" mapTo="UnityDAL.UnityDemoDataContextFactory, UnityDAL" /> <type type="UnityDAL.Interfaces.IProductRepository, UnityDAL" ...

ASP.NET MVC 3 beta: TryUpdateModel throws NullreferenceException in unit test

Hi, Since I updated to ASP.NET MVC 3 Beta 1, I get a NullReferenceException whenever I call TryUpdateModel() during a unit test session. The stack trace looks like this: Execute System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(Con...

Saving Data with the Factory Pattern?

I've been becoming more familiar with the Factory Pattern (along with Strategy Pattern) and what a great benefit the pattern can have. However, I've been struggling with the following situation: Previously, I would have done something like the following, where there's a manager class that would build and save a Car. There's no depende...

Calling Method of a Class within StructureMap Registry Configuration

I can't help but think there is a better way to do this than my current code within my StructureMap Registry. For<ISchedulerFactory>().Use(() => new StdSchedulerFactory()); For<IScheduler>().Use(() => new StdSchedulerFactory().GetScheduler()); Is there a way to have it use the previous registered type and call the method from that...