- ABP Framework version: v5.1.3
- UI type: MVS
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): Tiered MVC
Is it possible to call one of my Application Services (that returns a List collection from values from the DB) within a class that inherits from the PermissionDefinitionProvider to dynamically create PermissionDefinition objects? I create an instance of my application service using the **var permissionService = context.ServiceProvider.GetRequiredService(); **statement but after the service calls the supporting repository lookup I get an "Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed."
This same application service/method is used elsewhere in my application without any issues, so it appears to not work when I use it within a class that inherits from the PermissionDefinitionProvider class.
This exception was originally thrown at this call stack: Autofac.Core.Lifetime.LifetimeScope.CheckNotDisposed() Autofac.Core.Lifetime.LifetimeScope.BeginLifetimeScope(object) Autofac.Core.Lifetime.LifetimeScope.BeginLifetimeScope() Autofac.Extensions.DependencyInjection.AutofacServiceScopeFactory.CreateScope() Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(Volo.Abp.DynamicProxy.IAbpMethodInvocation) in UnitOfWorkInterceptor.cs System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task) System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter.InterceptAsync(Castle.DynamicProxy.IInvocation, Castle.DynamicProxy.IInvocationProceedInfo, System.Func<Castle.DynamicProxy.IInvocation, Castle.DynamicProxy.IInvocationProceedInfo, System.Threading.Tasks.Task>) ... [Call Stack Truncated]
12 Answer(s)
-
0
Can you share your code or steps? thanks.
-
0
What is you email address and I'll share a repo with you
-
0
shiwei.liang@volosoft.com
-
0
I've added you to it.
Run the dbmigrator to create and seed the DB then run the tiered layers
-
0
Thanks, I will check it out.
-
0
Any update on this?
Thanks
-
0
Method
Define
of classPermissionDefinitionProvider
is not an async method.You can try this:
public override void Define(IPermissionDefinitionContext context) { var permissionService = context.ServiceProvider.GetRequiredService<IPermAppService>(); var myGroup = context.AddGroup(VoloTestPermissions.GroupName); myGroup.AddPermission(VoloTestPermissions.Dashboard.Host, L("Permission:Dashboard"), MultiTenancySides.Host); myGroup.AddPermission(VoloTestPermissions.Dashboard.Tenant, L("Permission:Dashboard"), MultiTenancySides.Tenant); var permissions = AsyncHelper.RunSync(()=> permissionService.GetPermissionListAsync(new GetPermissionInput())) ; //foreach (var perm in permissions) //{ // myGroup.AddPermission($"{perm.Name}.Allow", L($"{perm.Name}.Allow")); // myGroup.AddPermission($"{perm.Name}.Deny", L($"{perm.Name}.Deny")); }
-
0
Still does not resolve the issue. Did you try it after to changed the things you recommended?
-
0
Of course, it works for me.
-
0
Let me see if I can't figure out why it still does not work. Can you update the repo with your changes applied please?
-
0
-
0
Thank you. That was the issue.