I have a small framework with Client/Server Architecture I use this Tools in my Business Layer:
DI = SimpleInjector
DynamicProxy For Interception = Castle.Core
now i need to validate some validations! for example look at this method:
public void DeleteFakeItem (Guid userId, Guid fakeItemId)
{
userAccountService.IsAuthorized(userId, FeatureIndex.DeleteFakeItem);
if (fakeItemId == Guid.EmptyGuid || userId == Guid.EmptyGuid)
throw new ArgumentNullException("parameters are not correct!");
if (!repo.IsFakeItemIsDeletable(fakeItemId))
throw new Exception("you can not delete this item!");
var fakeItem = repo.GetFakeItem(fakeItemId);
if (fakeItem == null)
throw new Exception("this fakeItem dose not exists!");
repo.DeleteActivityCenter(fakeItem);
}
but, i have a lot of methods, my methods are very different to each other, so where is the solution? because i can not create a good abstraction for my methods.
how can i implement a cross cutting feature to validate my parameters?
i think i can do it using interceptor and attributes, for example an attribute like [Validate(ValidateEnum.NotNull)]
for each parameter.
what is the correct way?
and second question for my entities: can i get the fluent API validation Rules to validate entities based on them using reflection with a interceptor?
for example i wanna get rules, if there is a IsRequired()
rule, validate as not null.
i don't wanna use decorator pattern because it's makes me refactoring a lot;