-
-
Notifications
You must be signed in to change notification settings - Fork 127
Description
I have a class and multiple interface as below:
public interface IWebUser1 { string GerWebUser(); }
public interface IConsumerUser2 { string GetConsumerUser(); }
public interface ISchedulerUser3 { string GetSchedulerUser(); }
public interface IUser : IWebUser1, IConsumerUser2, ISchedulerUser3 { string GetUser(); }
public class User : IUser
{
public string UserName { get; set; }
public string GerWebUser() => $"Executed IWebUser1 , User: {UserName ?? ""}";
public string GetConsumerUser() => $"Executed IConsumerUser2, User: {UserName ?? ""}";
public string GetSchedulerUser() => $"Executed ISchedulerUser3, User: {UserName ?? ""}";
public string GetUser() => $"Executed IUser, User: {UserName ?? ""}";
}
I have registered it using DryIoc provider as below:
// Register services with service key
container.RegisterMany(Reuse.Scoped);
Now when my code execute, it first goes to Middleware where i am resolving IUser using context accessor and able to get its instance and assigning UserName.
Now it goes into my controller where i am executor handler via MediatorR and it goes into my central Executor.
In this Executor class, when i am trying to resolve IUser using IServiceProvider.GetSerivce, i am getting null reference exception.
Above is working in .Net 6 but after upgrading to .Net 8, it is not working as i have got some information about changes related to scope validation strictness when it is registered using RegiserMany with Reuse Scope.
What is the solution around this as i have tried all possible ways like:
- Giving servicekey null
- Trying to individual register all interface but in that case User service is getting registered as seperate instance for each interface