dependency-injection

Post-injection initialisation (JSF 1.2 + Guice)

I'm trying to integrate Guice into a JSF 1.2 (Sun RI) application, and I want to be able to do the following to my managed-beans: Inject dependencies using the Guice @Inject annotation, then Perform initialisation using the @PostConstruct annotation My problem is that the @PostConstruct method is always invoked before the @Inject ann...

Using Unity Framework, inject into System.Windows.Forms.Form page

I have a form: public partial class mdiAuthenticationForm : Form { public Services.Authentication.IAuthentication Authenticator { get; set; public Services.Authentication.IAuthorization Authorizor { get; set; } and I want to inject concrete classes for the two attributes above. I have a type for each of them, and...

Should static classes be avoided because it makes Dependency Injection Difficult?

Somebody tasked with creating a "Core" set of libraries created a set of static classes providing all sorts of utilities from logging, auditing and common database access methods. I personally think this stinks because we now have a Core set of libraries that are hard to test because I can't mock / stub these classes or do any injection...

Where can I find large php5 best practises project?

I'm trying to find a project that incorporates the "best practices" that are discussed and debated on a daily basis for almost all languages but I'm trying to focus on php5. Is there a php5 open source project that I can comb through to see working examples of project that exemplifies Units Tests, Dependency Injection and other best pra...

Inject same DataContext instance across several types with Unity

Suppose I have IRepository interface and its implementation SqlRepository that takes as an argument LINQ to SQL DataContext. Suppose as well that I have IService interface and its implementation Services that takes three IRepository, IRepository and IRepository. Demo code is below: public interface IRepository<T> { } public class SqlRe...

interface<T> binding in Castle Windsor

Hi all. I have a common datacontainer interface IDataContainer I use it for different types of T IPerson, ISuperMan etc In castle i regsiter it with container.AddComponentWithLifestyle<IDataContainer<IPerson>, DataContainer<Person>>(LifestyleType.Transient); container.AddComponentWithLifestyle<IDataContainer<ISuperMan>, DataContain...

How to inject a Converter in XAML

I have an IValueConverter implemented class and I need it to be injected using my DI container (Ninject). The problem is, in XAML, there's no immediately obvious way to get control over the instantiation of the Converter object. So my XAML contains a line something like this: Source="{Binding Path=CurrentMessage, Converter={StaticR...

Has anyone used ServiceLoader together with Guice?

I keep wanting to try this on a larger scale with our app + build system, but higher priorities keep pushing it to the back burner. It seems like a nice way to load Guice modules and avoids the common complaint about "hard coded configuration". Individual configuration properties rarely change on their own, but you will almost always hav...

Optional injection in EJB3 bean or runtime dependency checks

I want to define injection so that only if the injected interface has EJB it will be injected. This is used as a plug-in to the main EJB. How to do this? Is there some annotation for this? I can use @PostConstruct to manually "inject" the variable. But then I have to handle the dependencies by myself. How can I handle dependencies knowi...

Is dependency injection parameters for user settings ?

Most dependency injection frameworks support initializing the components being injected with various parameters, typically read from an XML configuration file. This seems like a very convenient place to store settings (like a server name, or a file path that the component will need). But is that the right way to go, or would it make mo...

In StructureMap, how can I change the InstanceScope at runtime?

In my DefaultRegistry I have this configuration: ForRequestedType<INHUnitOfWork>().CacheBy(InstanceScope.HttpContext) .TheDefault.Is.OfConcreteType<NHibernateUnitOfWork>(); At some point in the web application flow I want to change the InstanceScope to HttpSession to obtain a long conversation, so I do this: PluginTypeConfigu...

WPF Prism V2 Using M-V-VM - Add a view at runtime to a region from the ViewModel

Hi All, Hopefully quite a simple one, having my first try at WPF with Prism V2 using M-V-VM and so far finding everything pretty awsome. My Shell is pretty simple, Ribbon Control at the Top, DataGrid of Help desk tickets on the left, and a TabControl on the right. When a user opens the selected ticket from the datagrid, I want the Tic...

Can I inject a SessionBean into a JEE AroundInvoke-Interceptor?

I have an EAR with modules: foo-api.jar foo-impl.jar interceptor.jar In foo-api there is: @Local FooService // (interface of a local stateless session bean) In foo-impl there is: @Stateless FooServiceImpl implements FooService //(implementation of the foo service) In interceptor.jar I want public class BazInterceptor { @EJB...

Dependecy Injection and Class Inheritance

I feel like this is something I should already know, but I'm just not firing on all engines today... I have a base class with a single ctor that takes an implementation of an interface as it's only parameter. I'm using a DI framework and have my component registrations all set up and working fine. When I inherit from this base class, ...

.Net dependency injection on debug build using nant

Hi All, I have a relatively small app that Im building using vb.net 2.0, and nant. Its a app that calls out to an external exe to produce some output files, then processes those output files afterwards. I have built an interface to the exe, which I have created a stub implementation and the real implementation, what I would like to be ...

What are the advantages of using a concept like IStartable?

Instead of using an interface like this: public interface IStartable { void Start(); void Stop(); } I usually just make the constructor of an object run the Start() code, and implement IDisposable so that the dispose method runs the Stop() code. Is it just a matter of style? Or am I missing something important by not having s...

Illustration for code presentation

I got an odd request, and I fear it will be closed as off-topic. So be it, but it's worth a shot. I'm creating a presentation about dependency injection and inversion of control, and I thought I'd make the point of interchangeable parts that serve a common purpose, but has different implementations, by showing an image I've seen before....

Are there other benefits to loosely coupled code besides TDD?

When I'm doing TDD, it forces me to employ Dependency Injection principle and I end up with loosely coupled code. I was told that it's harder to understand application that has loosely coupled code. Can you tell me what pros and cons of loosely coupled code? ...

Using Spring to inject EasyMock mocks causes ClassCastException

I am trying to get Spring to inject EasyMock mocks in my unit tests. In my applicationContext.xml, I have this: <bean id="mockService" class="org.easymock.EasyMock" factory-method="createMock" name="MockService"> <constructor-arg index="0" value="my.project.Service"/> </bean> In my unit test I have this: @Autowired @Qualifier(...

Inject a MembershipProvider into ASP.Net MVC AccountController

Asp.Net MVC 1.0 project templates include an AccountController class, which supports constructor injection: public AccountController(IFormsAuthentication formsAuth, IMembershipService service) { FormsAuth = formsAuth ?? new FormsAuthenticationService(); MembershipService = service ?? new AccountMembershipService(); } An A...