using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Transactions;
using Abp.Application.Services;
using Abp.Domain.Repositories;
namespace Abp.Domain.Uow
{
internal class UnitOfWorkDefaultOptions : IUnitOfWorkDefaultOptions
{
public TransactionScopeOption Scope { get; set; }
///
public bool IsTransactional { get; set; }
///
public TimeSpan? Timeout { get; set; }
///
public bool IsTransactionScopeAvailable { get; set; }
///
public IsolationLevel? IsolationLevel { get; set; }
public IReadOnlyList Filters => _filters;
private readonly List _filters;
public List> ConventionalUowSelectors { get; }
public UnitOfWorkDefaultOptions()
{
_filters = new List();
IsTransactional = true;
Scope = TransactionScopeOption.Required;
IsTransactionScopeAvailable = true;
ConventionalUowSelectors = new List>
{
type => typeof(IRepository).IsAssignableFrom(type) ||
typeof(IApplicationService).IsAssignableFrom(type)
};
}
public void RegisterFilter(string filterName, bool isEnabledByDefault)
{
if (_filters.Any(f => f.FilterName == filterName))
{
throw new AbpException("There is already a filter with name: " + filterName);
}
_filters.Add(new DataFilterConfiguration(filterName, isEnabledByDefault));
}
public void OverrideFilter(string filterName, bool isEnabledByDefault)
{
_filters.RemoveAll(f => f.FilterName == filterName);
_filters.Add(new DataFilterConfiguration(filterName, isEnabledByDefault));
}
}
}