package com.hongyegroup.zhurijob.di

import android.app.Application
import com.google.gson.Gson
import com.hjq.gson.factory.GsonFactory
import com.hongyegroup.zhurijob.app.MyApplication
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 * 全局的DI注入
 */
@Module
@InstallIn(SingletonComponent::class)
class ApplicationModule {

    //如果是自己定义的MyApplication，通过一个Module向下转型
    @Provides
    fun provideMyApplication(application: Application): MyApplication {
        return application as MyApplication
    }

    //全局的Gson  使用框架进行容错处理
    @Provides
    @Singleton
    fun provideGson(): Gson {
        return GsonFactory.getSingletonGson()
    }

}