Giter Club home page Giter Club logo

ray's Introduction

Ray

Ray is a light-weight dependency injection container implementation. It was created for research purposes and does not support most of the features, that are present in Spring, Tapestry or PicoContainer. However, several applications were created using Ray.

Ray project is separated into modules to make the result jar size as light as possible.

  • ray-core (core API)
  • ray-annotation (annotation context implementation)
  • ray-json (json context implementation)
  • ray-xml (xml context implementation)
  • ray-txt-common (common tools for txt based contexts)

The minimun set of libraries you need is ray-core + any context implementation module.

Supported features:

  • Context of managed components (annotations, xml, json)
  • Singleton and Prototype scopes
  • As-Is component injection
  • PostConstruct and PreDestroy lifecycle hooks
  • Profiles for different deployment environments

Examples:

Annotation based context

MyBean.java

package com.myproject.core;

import org.skywind.ray.meta.ManagedComponent;

@ManagedComponent("greeter");
public class Greeter {

   @Inject
   private OtherBean otherBean;

   public void sayHello() {
       System.out.println("Hello, " + otherBean.getName());
   }
}

Main.java

import org.skywind.ray.core.AnnotationContext;
import org.skywind.ray.core.BeanContainer;
import org.skywind.ray.core.Context;
    
public class Main {

   public static void main(String[] args) {
       Context context = new AnnotationContext("com.myproject.core");
       context.refresh();

       BeanContainer beanContainer = context.getBeanContainer();
       Greeter greeter = beanContainer.getBean("greeter");
       greeter.sayHello();
   }
}

JSON based context

context.json

{
    "beans" : [
        {
            "id" : "greeter",
            "class" : "com.myproject.core.Greeter",
            "scope" : "singleton",
            "autowired" : ["otherBean"]
        },
        {
            "id" : "otherBean",
            "class" : "com.myproject.core.OtherBean",
            "scope" : "singleton"                
        }            
    ]
}

Main.java

import org.skywind.ray.core.JsonContext;
import org.skywind.ray.core.BeanContainer;
import org.skywind.ray.core.Context;

public class Main {

   public static void main(String[] args) {
       Context context = new JsonContext("classpath:context.json");
       context.refresh();

       BeanContainer beanContainer = context.getBeanContainer();
       Greeter greeter = beanContainer.getBean(Greeter.class);
       greeter.sayHello();
   }
}

XML based context

context.xml

<context xmlns="ray-context">
   <bean id="greeter" 
         class="com.myproject.core.Greeter" 
         autowired="otherBean"/>

   <bean id="otherBean" 
         class="com.myproject.core.OtherBean"/>       
</context>

Main.java

import org.skywind.ray.core.XmlContext;
import org.skywind.ray.core.BeanContainer;
import org.skywind.ray.core.Context;

public class Main {

   public static void main(String[] args) {
       Context context = new XmlContext("classpath:context.xml");
       context.refresh();

       BeanContainer beanContainer = context.getBeanContainer();
       Greeter greeter = beanContainer.getBean(Greeter.class);
       greeter.sayHello();
   }
}

ray's People

Contributors

sergey-sw avatar

Watchers

Akshat Kumar avatar James Cloos avatar  avatar

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.