So, I'm honestly not even sure how to ask this question, since I lack experience in this topic. If there is information missing, just let me know and I'll add all I have.
I'm basically trying to add an Exception handling system in my web application by using a filter.
So below you can see the filter I created. In here I'm trying to reach my unitofwork, but I keep getting an exception on the container.Resolve<IUnitOfWork>();
line.
public class LogExceptionFilterAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext context)
{
var dependencyResolver = GlobalConfiguration.Configuration.DependencyResolver
as AutofacWebApiDependencyResolver;
var container = dependencyResolver.Container;
var uow = container.Resolve<IUnitOfWork>();
}
}
The exception I'm getting:
DependencyResolutionException was unhandled by user code
An exception of type 'Autofac.Core.DependencyResolutionException' occurred in Autofac.dll but was not handled in user codeAdditional information: No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.
Here is the IUnitOfWork interface:
public interface IUnitOfWork : IDisposable
{
IBoothRepository BoothRepository { get; }
IEventRepository EventRepository { get; }
ILocationRepository LocationRepository { get; }
IPersonRepository PersonRepository { get; }
IProfessionalRepository ProfessionalRepository { get; }
IRegistrationRepository RegistrationRepository { get; }
IStakeholderRepository StakeholderRepository { get; }
IStudentRepository StudentRepository { get; }
IVisitRepository VisitRepository { get; }
void SaveChanges();
DbContextTransaction BeginTransaction();
}