Giter Site home page Giter Site logo

alchemy-inject's Introduction

Alchemy Inject

Overview

A guice module discovery module with support for multiple environments. Alchemy Inject tries to deal with the problem of creating guice injector in a reliable and decentralized manner. The idea is to write a guice module and mark it with an environment it is relevant it and it should be applied.

The injector also contains a discovery mechanism for discovering Jackson modules and auto injecting the ObjectMapper.

Usage

Adding gradle dependency

compile 'com.strandls.alchemy:alchemy-inject:0.9'


Adding maven dependency

<dependency>
	<groupId>com.strandls.alchemy</groupId>
	<artifactId>alchemy-inject</artifactId>
	<version>0.9</version>
</dependency>

Marking modules for discovery

You use Alchemy Inject by annotating your guice modules with the AlchemyModule annotation like so

import com.google.inject.AbstractModule;
import com.strandls.alchemy.inject.AlchemyModule;
import com.strandls.alchemy.inject.AlchemyModule.Environment;

/**
 * Bindings for authentication.
 *
 * @author ashish
 *
 */
@AlchemyModule(Environment.All)
public class AuthModule extends AbstractModule {
 .
 .
 .

A module is be annotated with an environment it is to be used in. Three values are supported today.

  • Prod - this module should be used in production settings
  • Test - this module should be used in test settings
  • All - this module should be used across both test and production settings

Creating the injector

Create a guice injector using all production modules, including modules annotated with environment All as well, like so

import com.google.inject.Injector;
import com.strandls.alchemy.inject.AlchemyModule.Environment;
import com.strandls.alchemy.inject.AlchemyModuleLister;

Injector injector = Guice.createInjector(new AlchemyModuleLister().getModules(Environment.Prod))

Note you can now keep adding newer guice modules without having to worry about changing the injector creatiion code.

Excluding modules while creating the injector

With large complex projects you might hit a case where you have conflicting bindings. With Alchemy inject you could resolve these bindings or filter out some modules using a configuration file placed in your application classpath.

The file, written in .ini format, should be named alchemy-modules.ini. Here is a sample file

[Prod]
filter=(?i).*dummy.*
filter=com.strandls.alchemy.webservices.auth.AuthModule

[Test]
filter=com.strandls.alchemy.webservices.client.StaticCredentialsModule
filter=com.strandls.alchemy.webservices.client.JaxRsClientModule

With this configuration file all modules with dummy (ignoring case) in there fully qualified class name, will be filtered out from the production environment. The filter expressions are [JavaRegex][Java regular expressions].

Demo

The Alchemy Rest Client Demo project is a good demostration of real life use of this module.

Contributing

Please refer to Contribution Guidlines if you are not familiar with contributing to open source projects.

The gist for making a contibution is

  1. Fork
  2. Create a topic branch - git checkout -b <your branch>
  3. Make your changes
  4. Push to your branch - git push origin <your branch>
  5. Create an [Issue] with a link to your branch

Setting up eclipse

Run

gradle/gradlew eclipse

Import alchemy inject to eclipse using File > Import > Existing Projects into Workspace

The project has been setup to auto format the code via eclipse save actions. Please try not to disturb this.

Copyright and license

Code and documentation copyright 2015 Strand Life Sciences. Code released under the Apache License 2.0. Docs released under Creative Commons.

alchemy-inject's People

Contributors

ashishshinde avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jtraver

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.