C
C#11mo 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
TheRanger11mo 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
Elio11mo ago
oh sounds great didn't think to do this way i'll try it thanks !
Denis
Denis11mo ago
If this issue is solved, consider closing this thread using /close