I think the specifics of my question are very much different than the other similar questions which I have red.
I know that when I have custom AuthorizeAttribute I can't inject dependencies with the constructor. This is because the constructor will take the parameters - in my case the permission strings.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class UserAllCSPermissionBasedAuthFilter : AuthorizeAttribute
{
I am depending on authorization service, that's why I am injected that using property injection.
[Inject]
public IAuthorizationService _authorizationService { get; set; }
The problem is that this service depends on another service - userservice which talks directly with repository and dbcontext. I have specify for my db context to live in request scope. This is cousing an exception - "The operation cannot be completed because the DbContext has been disposed." When I looked at the code this is happening when the autorization service calls userservice which asks the dbcontext for some data. How should I avoid this happening?
public class AuthorizationService : IAuthorizationService
{
private readonly ICommonRepository _commonRepository;
private readonly IRepositoryBase<UsersInRolesEntity> _repositoryUsersInRoles;
private readonly IRepositoryBase<UserCustomerRolesEntity> _repositoryCurstomerRoleEntities;
private readonly ISqlCustomersRepository _sqlCustomerRepository;
private readonly IRoleService _roleService;
private readonly IUserService _userService;
private readonly IPermissionService _permissionService;
public AuthorizationService(
IRepositoryBase<UsersInRolesEntity> repositoryUsersInRoles,
IRepositoryBase<UserCustomerRolesEntity> repositoryCurstomerRoleEntities,
ICommonRepository commonRepository,
ISqlCustomersRepository sqlCustomerRepository,
IRoleService roleService,
IUserService userService,
IPermissionService permissionService
)
{