Autofac父类和子类实现相同的接口

时间:2018-11-19 12:40:35

标签: autofac autofac-module

我想解析一个将子类作为参数并都实现相同接口的父类。

我应该如何编写AutoFac引导程序文件来解析EmailNotifier?

当我尝试解决时,出现循环依赖错误。以下是代码。我已经尝试过builder.RegisterAssemblyTypes,这只会带来子实现

class ApplicationAuthenticator(private val context: Context) : AbstractAccountAuthenticator(context) {

    // Editing properties is not supported
    @Throws(UnsupportedOperationException::class)
    override fun editProperties(response: AccountAuthenticatorResponse,
                                accountType: String): Bundle? {

        throw UnsupportedOperationException()
    }

    // Don't add additional accounts
    override fun addAccount(response: AccountAuthenticatorResponse, accountType: String,
                            authTokenType: String, features: Array<String>,
                            options: Bundle): Bundle? {

        return bundleOf(AccountManager.KEY_INTENT to null)
    }

    // Ignore attempts to confirm credentials
    @Throws(NetworkErrorException::class)
    override fun confirmCredentials(response: AccountAuthenticatorResponse, account: Account,
                                    options: Bundle): Bundle? {

        return null
    }

    // Getting an authentication token is not supported
    @Throws(NetworkErrorException::class, UnsupportedOperationException::class)
    override fun getAuthToken(response: AccountAuthenticatorResponse, account: Account,
                              authTokenType: String, loginOptions: Bundle): Bundle? {

        throw UnsupportedOperationException()
    }

    // Getting a label for the auth token is not supported
    override fun getAuthTokenLabel(authTokenType: String): String {
        return context.resources.getString(R.string.application_name)
    }

    // Updating user credentials is not supported
    override fun updateCredentials(response: AccountAuthenticatorResponse, account: Account,
                                   authTokenType: String, loginOptions: Bundle): Bundle? {

        return null
    }

    // Checking features for the account is not supported
    @Throws(NetworkErrorException::class)
    override fun hasFeatures(response: AccountAuthenticatorResponse, account: Account,
                             features: Array<String>): Bundle {

        return bundleOf(KEY_BOOLEAN_RESULT to false)
    }

}

0 个答案:

没有答案