- 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.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
shiwei.liang@volosoft.com
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Thanks, I will check it out.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Method
Defineof classPermissionDefinitionProvideris 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")); }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Of course, it works for me.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
