2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.wicket.inject;
18 import org.apache.wicket.Component;
19 import org.apache.wicket.application.IComponentInstantiationListener;
20 import org.apache.wicket.protocol.http.WebApplication;
21 import org.wamblee.inject.InjectorBuilder;
22 import org.wamblee.inject.SimpleInjector;
26 * Component instantiation listener that injects references into a component
27 * using the injector mini-framework. Together with an implementation of the
28 * mini-framework, Contexts and Dependency Injection support can be provided or
29 * for standard Java EE injection into components. Or, other injection
30 * frameworks can be used.
34 * To use this injector override {@link WebApplication#init()} and add the
39 * protected void init() {
41 * addComponentInstantiationListener(new ComponentInstantiationInjector());
45 * @author Erik Brakkee
47 public class ComponentInstantiationInjector implements
48 IComponentInstantiationListener {
50 private SimpleInjector injector;
53 * Constructs the component instantiation listener.
55 public ComponentInstantiationInjector() {
56 injector = new SimpleInjector(InjectorBuilder.getInjectorFactory());
60 public void onInstantiation(Component aComponent) {
61 injector.inject(aComponent);