问题描述
我正在尝试通过使用注入来获取实用程序方法的ResourceLoader,但我不断收到以下错误:
public void ConfigureAuth(IAppBuilder app)
{
IdentityModelEventSource.ShowPII = true;
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// Generate the metadata address using the tenant and policy information
MetadataAddress = String.Format(Globals.WellKnownMetadata,Globals.Tenant,Globals.DefaultPolicy),// These are standard OpenID Connect parameters,with values pulled from web.config
ClientId = Globals.ClientId,RedirectUri = Globals.RedirectUri,PostLogoutRedirectUri = Globals.RedirectUri,// Specify the callbacks for each type of notifications
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = OnRedirectToIdentityProvider,AuthorizationCodeReceived = OnAuthorizationCodeReceived,AuthenticationFailed = OnAuthenticationFailed,},// Specify the claim type that specifies the Name property.
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",ValidateIssuer = false
},// Specify the scope by appending all of the scopes requested into one string (separated by a blank space)
Scope = $"openid profile offline_access {Globals.ReadTasksScope} {Globals.WriteTasksScope}"
});
}
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property resourceResolver has not been initialized
我不需要使用注入来实现这一目标,我只需要从parseYaml方法访问ResourceResolver。
解决方法
我不需要使用注射来实现这一目标
您确实需要使用注射剂。这就是为什么您的代码使用@Inject
的原因。
问题是您正在创建Injections
的新实例,而不是使用容器提供的实例,因此您的实例将无法按照您希望的方式进行初始化。如果您将val inj = Injections()
实例@Inject
放入需要访问它的任何bean中,则可以代替Injections
。