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

com.github.zhangchengji.FlyingInject Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.zhangchengji;

import com.github.zhangchengji.factory.DefaultPropertiesFactory;
import com.github.zhangchengji.factory.PropertiesFactory;
import com.google.inject.AbstractModule;

import com.google.inject.Guice;
import com.google.inject.Singleton;

public class FlyingInject  {
    private static volatile com.google.inject.Injector f_injector;
    private static final Object lock = new Object();

    private static com.google.inject.Injector getInjector() {
        if (f_injector == null) {
            synchronized (lock) {
                if (f_injector == null) {
                    try {
                        f_injector = Guice.createInjector(new FlyingModule());
                    } catch (Throwable ex) {

                    }
                }
            }
        }
        return f_injector;
    }



    public static   T getInstance(Class aClass) {
        return getInjector().getInstance(aClass);
    }


    public static  T getInstance(Class clazz, String name) {
        return null;
    }


    private static class FlyingModule extends AbstractModule {
        @Override
        protected void configure() {
            bind(PropertiesFactory.class).to(DefaultPropertiesFactory.class).in(Singleton.class);
            super.configure();
        }
    }
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy