khs-sherpa-guice

Guice support for Sherpa.

Лицензия

Лицензия

Категории

Категории

GUI Взаимодействие с пользователем Guice Библиотеки уровня приложения Dependency Injection KeY Данные Data Formats Formal Verification
Группа

Группа

com.keyholesoftware
Идентификатор

Идентификатор

khs-sherpa-guice
Последняя версия

Последняя версия

1.3.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

khs-sherpa-guice
Guice support for Sherpa.
Ссылка на сайт

Ссылка на сайт

http://keyholesoftware.com
Организация-разработчик

Организация-разработчик

Keyhole Software
Система контроля версий

Система контроля версий

https://github.com/in-the-keyhole/khs-sherpa-guice

Скачать khs-sherpa-guice

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.keyholesoftware/khs-sherpa-guice/ -->
<dependency>
    <groupId>com.keyholesoftware</groupId>
    <artifactId>khs-sherpa-guice</artifactId>
    <version>1.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.keyholesoftware/khs-sherpa-guice/
implementation 'com.keyholesoftware:khs-sherpa-guice:1.3.0'
// https://jarcasting.com/artifacts/com.keyholesoftware/khs-sherpa-guice/
implementation ("com.keyholesoftware:khs-sherpa-guice:1.3.0")
'com.keyholesoftware:khs-sherpa-guice:jar:1.3.0'
<dependency org="com.keyholesoftware" name="khs-sherpa-guice" rev="1.3.0">
  <artifact name="khs-sherpa-guice" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.keyholesoftware', module='khs-sherpa-guice', version='1.3.0')
)
libraryDependencies += "com.keyholesoftware" % "khs-sherpa-guice" % "1.3.0"
[com.keyholesoftware/khs-sherpa-guice "1.3.0"]

Зависимости

provided (4)

Идентификатор библиотеки Тип Версия
javax.servlet : javax.servlet-api jar 3.1.0
com.keyholesoftware : khs-sherpa jar 1.3.0
com.google.inject : guice jar 3.0
com.google.inject.extensions : guice-servlet jar 3.0

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.8.1

Модули Проекта

Данный проект не имеет модулей.

khs-sherpa-guice Build Status

Google Guice dependency injection integration for khsSherpa.

Link to khsSherpa project here...[https://github.com/in-the-keyhole/khs-sherpa]

Getting Started

To get this working, follow these steps:

Add

<listener>
    <listener-class>com.khs.guice.SherpaGuiceContextListener</listener-class>
</listener>

to your web.xml after Sherpa's listener but before your application's listener.

In your application's context listener, add SherpaGuiceModule to the end of the list of modules to be loaded by the injector. Then, use something like this to let the SherpaGuice's factory know about the injector. Also shown is how to have Guice handle your servlet mapping without having to put it in web.xml.

After these "glue" pieces are in place, you can just use @Inject in your Sherpa endpoints to inject services or whatever else you need.

public class MyApplicationContextListener extends GuiceServletContextListener implements ServletContextListener {
	private List<Module> modulesLoaded = new LinkedList<Module>();
	ServletContext servletContext;

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		servletContext = sce.getServletContext();
		super.contextInitialized(sce);
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		super.contextDestroyed(sce);
		for (Module module : modulesLoaded) {
			if (module instanceof DestroyableModule) {
				((DestroyableModule) module).destroy();
			}
		}

		servletContext = null;
	}

	@Override
	protected Injector getInjector() {
		// add your application modules here
	
		modulesLoaded.add(new ServletModule() {
			@Override
			protected void configureServlets() {
				serve("/api/*").with(SherpaGuiceServlet.class);
			}
		});
		modulesLoaded.add(new SherpaGuiceModule());

		ApplicationContext applicationContext = (ApplicationContext)servletContext.getAttribute(GenericApplicationContext.SHERPA_APPLICATION_CONTEXT_ATTRIBUTE);
		SherpaGuiceManagedBeanFactory factory = (SherpaGuiceManagedBeanFactory) applicationContext.getManagedBeanFactory();
		Injector injector = Guice.createInjector(modulesLoaded);
		factory.setInjector(injector);
		return injector;
	}
}
com.keyholesoftware

Keyhole Software

Software dev team providing consulting, development & education services with Java, JavaScript & .NET technologies.

Версии библиотеки

Версия
1.3.0