C
C#16mo ago
Elio

✅ Singleton Class

Do you know if there is a way to call a method each time i retrieve my singleton class this way : services.GetRequiredService<MaterialDetailsViewModel>() I want to reset 1 variable each time i call this singleton with GetRequiredService
3 Replies
TheRanger
TheRanger16mo ago
i would define an extension method for services's class eg
public static T GetRequiredService2<T>(this IServiceProvider provider)
{
yourVariable = 0;
return provider.GetRequiredService<T>();
}
public static T GetRequiredService2<T>(this IServiceProvider provider)
{
yourVariable = 0;
return provider.GetRequiredService<T>();
}
Elio
ElioOP16mo ago
oh sounds great didn't think to do this way i'll try it thanks !
Denis
Denis16mo ago
If this issue is solved, consider closing this thread using /close
Want results from more Discord servers?
Add your server