Skip to content

Java FrameworkCore to kickstart you applications!

Notifications You must be signed in to change notification settings

N3cr0s1s/FrameworkCore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

Framework Core

A framework core, to kickstart your Java applications!

Created by: Necrosis


Report Bug · Request Feature

About The Project

This repository created because I need this tools in my projects, and I don't like boilerplate code.
This is a personal tool, but I thought I'd make it public in case someone could use it.

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

  • Maven (This is not working yet!...)
    <dependency>
      <groupId>me.necrosis.fwc</groupId>
      <artifactId>fw-core</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

Create a framework

To create a new framework, just create a new class, and extend with the FrameworkCore.

public class MyFramework extends FrameworkCore {
  //    ...
}

Important

FrameworkCore has a constructor which is requires one arg, which is FwOption.
With this object, you can specify FW options.
I recommend to use this constructor, but there is a default one either.

Modules (Dependency injection)

Framework main function is the Dependency Injection (DI). It's useful because you don't need to handle services life cycles.

Before you do anything else, you need to override some method.
Firstly you need to Override the configureServices. This method returns with a new AbstractModule. This module will be used by Dependency Injection (DI).

public class MyFramework extends FrameworkCore {

  @Override
  public AbstractModule configureServices() {
    return new AbstractModule() {
      @Override
      protected void configure() {
          // There you can register your services like this:
        
          // bind(INTERFACE).to(IMPLEMENTATION).in(SCOPE)
          bind(TransientService.class).to(TransientServiceImpl.class).in(Scopes.NO_SCOPE);
          bind(SingletonService.class).to(TransientServiceImpl.class).in(Scopes.SINGLETON);
          
          // You can register services without interface with:
          bind(TestClass.class).in(Scopes.SINGLETON);
      }
    };
  }
   
  // ...
}

To get services you can use :

public class MyFramework extends FrameworkCore {
  //...
  public void nothing(){
    TransientService transientService = getInjector().getInstance(TransientService.class);
  }
  //...
}

OnStart

To start you framework Override the onStart method.
This method will run right after the framework init, but you can overwrite this with the FwOptions. Just make sure your FwOptions#autoStart is false.

Warning

If you are using FwOptions#autoStart with false, then don't forget to call FrameworkCore#handleStart method! This method handle the full Start/Stop cycle and Exception handling.

OnEnd

OnEnd method will execute after the OnStart method. This method gives you one argument, which is a boolean. This boolean is true if the start method ended with an exception, otherwise false.

OnFwException

OnFwException this will catch all exceptions that occurred in the onStart method or the onEnd method.
This will give you 2 args, first is the Thread, second is a FwException. To get the real exception, use this: FwException#getException()

Plugins

You can create plugins for the framework. To register a plugin use the FrameworkCore#registerPlugins() method.
This method need to return with a list of the plugins.

In FrameworkCore plugins basically just a new AbstractModule, which is a DI module.

Examples

For examples see the test project. (fw-test)

Contributing

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Releases

No releases published

Packages

No packages published

Languages