Git Product home page Git Product logo

magic-ioc-container's Introduction

Magic-IoC-Container

Custom made dependency container replicating the functionality of Spring Boot.

Main Features

  • Create instance of your services
  • Automatically resolve dependencies
  • Create Beans
  • Add your own custom mapping annotations for services and beans
  • Manage instantiated services (get them by annotation, qualifier, type)
  • Reload instantiated services
  • Handle custom service and bean scopes by using proxies.
  • Enrich your service with aspects

The Goal

This project is created with the purpose to help understand how IoC Containers work under the hood. There is a video series on youtube where I am building this project: https://www.youtube.com/watch?v=JHxFJwxb0FQ

  • Note that after the video I've made changes to the app so if you are coming from there, please checkout to the following commit to be able to follow more easily.
  • commit hash: 4ba9ad9eee6014598e356f2bb16e6819e53948fb -> Added project source code.

How to run the app?

  • Run 'mvn package' and get the generated jar file.
  • Import it into your project
  • In your main method call 'MagicInjector.run(YourStartupClass.class);'
  • Annotate your startup class with @Service
  • Create a void method and annotate it with @StartUp

You can also run the app with 'MagicInjector.run(YourStartupClass.class, new MagicConfiguration());'.

Supported annotations by default:

  • Bean - Specify bean producing method.
  • Service - Specify service.
  • Autowired - Specify which constructor will be used to create instance of a service. also you can annotate fields with this annotation.
  • PostConstruct - Specify a method that will be executed after the service has been created.
  • PreDestroy - Specify a method that will be executed just before the service has been disposed.
  • StartUp - Specify the startup method for the app.
  • AliasFor - You can use this annotation to integrate your own annotations with MagicInjector AliasFor works with Autowired, NamedInstance, Nullable, PostConstruct, PreDestroy, Qualifier.
  • NamedInstance - Specify the name of the service / bean.
  • Nullable - required dependency can be null.
  • Qualifier - Specify the name of the dependency that you are requiring.
  • Scope - Specify the scope of the service. SINGLETON, PROTOTYPE or PROXY.

You can use the configuration to provide custom annotations that can act like @Bean and @Service.

The benefit of that is that you might have some services that you might want to filter out by something and custom annotations is a good approach.

Also you can access the DependencyContainer instance this way 'DependencyContainer dc = MagicInjector.run(...)' or by requiring it from the startup method.

Documentation

Currently there is no real documentation from where you can read, but you can read the javadoc or you can check out the integration tests located here. Also you can check out Java Web Server where this app is heavily utilized from the MVC framework.

More info

If you are having trouble running the app, contact me at [email protected] .

magic-ioc-container's People

Contributors

cyecize 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.