All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spincast.plugins.session.SpincastSessionPluginModule Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package org.spincast.plugins.session;

import java.util.Set;

import org.spincast.core.guice.SpincastGuiceModuleBase;
import org.spincast.plugins.scheduledtasks.SpincastScheduledTask;
import org.spincast.plugins.session.config.SpincastSessionConfig;
import org.spincast.plugins.session.config.SpincastSessionConfigDefault;
import org.spincast.plugins.session.config.SpincastSessionPluginScheduledTaskProvider;
import org.spincast.plugins.session.config.SpincastSessionPluginScheduledTaskProviderDefault;
import org.spincast.plugins.session.repositories.SpincastSessionRepositoryDefault;

import com.google.inject.Key;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.multibindings.Multibinder;

/**
 * Spincast Session plugin module.
 */
public class SpincastSessionPluginModule extends SpincastGuiceModuleBase {

    @Override
    protected void configure() {

        bind(SpincastSessionConfig.class).to(getSpincastSessionConfigImplClass())
                                         .in(Scopes.SINGLETON);

        bind(SpincastSessionManager.class).to(getSpincastSessionManagerImplClass())
                                          .in(Scopes.SINGLETON);

        //==========================================
        // Filters to be added as soon as the app starts
        //==========================================
        bind(SpincastSessionFilterAdder.class).asEagerSingleton();

        install(new FactoryModuleBuilder().implement(SpincastSession.class,
                                                     getSpincastUserSessionImplClass())
                                          .build(SpincastSessionFactory.class));

        bind(SpincastSessionFilter.class).to(getSpincastSessionFilterImplClass())
                                         .in(Scopes.SINGLETON);

        //==========================================
        // Binds scheduled tasks
        //==========================================
        bind(SpincastSessionPluginScheduledTaskProvider.class).to(getSpincastSessionPluginScheduledTaskProviderImplClass())
                                                              .in(Scopes.SINGLETON);
        Multibinder> scheduledTaskSetsMultibinder =
                Multibinder.newSetBinder(binder(), Key.get(new TypeLiteral>() {}));
        scheduledTaskSetsMultibinder.addBinding().toProvider(SpincastSessionPluginScheduledTaskProvider.class);

        bind(SpincastSessionRepository.class).to(getSpincastSessionRepositoryImplClass())
                                             .in(Scopes.SINGLETON);
    }

    protected Class getSpincastSessionConfigImplClass() {
        return SpincastSessionConfigDefault.class;
    }

    protected Class getSpincastUserSessionImplClass() {
        return SpincastSessionDefault.class;
    }

    protected Class getSpincastSessionFilterImplClass() {
        return SpincastSessionFilterDefault.class;
    }

    protected Class getSpincastSessionPluginScheduledTaskProviderImplClass() {
        return SpincastSessionPluginScheduledTaskProviderDefault.class;
    }

    protected Class getSpincastSessionManagerImplClass() {
        return SpincastSessionManagerDefault.class;
    }

    protected Class getSpincastSessionRepositoryImplClass() {
        return SpincastSessionRepositoryDefault.class;
    }

    protected Class getSpincastSessionFilterAdderImplClass() {
        return SpincastSessionFilterAdder.class;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy