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

org.nutz.integration.hasor.NutzModule Maven / Gradle / Ivy

There is a newer version: 1.r.69.v20220215
Show newest version
/*
 * Copyright 2008-2009 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
 *
 *      http://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 org.nutz.integration.hasor;
import net.hasor.core.ApiBinder;
import net.hasor.core.BindInfo;
import net.hasor.core.Module;
import net.hasor.core.Provider;
import net.hasor.core.info.AbstractBindInfoProviderAdapter;
import org.nutz.ioc.Ioc;

import java.util.List;
/**
 * Nutz 版的 Module ,让开发者可以在 Hasor 的体系内访问到 Nutz 的 IoC 容器
 * @version : 2017年02月20日
 * @author 赵永春([email protected])
 */
public abstract class NutzModule implements Module {
    protected  Provider nutzBean(ApiBinder apiBinder, final Class beanType) {
        List> list = apiBinder.findBindingRegister(Ioc.class);
        BindInfo iocBindInfo = list.get(0);
        final Ioc ioc = (Ioc) ((AbstractBindInfoProviderAdapter) iocBindInfo).getCustomerProvider().get();
        return new Provider() {
            @Override
            public T get() {
                return ioc.get(beanType);
            }
        };
    }
    protected  Provider nutzBean(ApiBinder apiBinder, final Class beanType, final String name) {
        List> list = apiBinder.findBindingRegister(Ioc.class);
        BindInfo iocBindInfo = list.get(0);
        final Ioc ioc = (Ioc) ((AbstractBindInfoProviderAdapter) iocBindInfo).getCustomerProvider().get();
        return new Provider() {
            @Override
            public T get() {
                return ioc.get(beanType, name);
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy