Exception Handling Configuration

You can configure exception handling to behave in different ways. You can choose to throw all RepositoryBase exceptions so your upper layers can handle/log the exceptions (code block 1). Another option is to subscribe to the RepositoryBaseExceptionRaised event. Subcribing to this event will catch the RepositoryBase exceptions and raises the event with the catched exception (code block 2).

code block 1:

public class ProductRepository : RepositoryBase<RepositoryContext>, IProductRepository
    {
        public ProductRepository()
            : base(throwExceptions: true, useTransactions: true)
        {

        }
}

code block 2:

public class ProductRepository : RepositoryBase<RepositoryContext>, IProductRepository
    {
        public ProductRepository()
            : base(throwExceptions: false, useTransactions: true)
        {
            base.RepositoryBaseExceptionRaised += ProductRepository_RepositoryBaseExceptionRaised;
        }

        void ProductRepository_RepositoryBaseExceptionRaised(Exception exception)
        {
            throw new NotImplementedException();
        }
}

Last edited Oct 9, 2012 at 10:04 AM by MMMicha, version 3

Comments

No comments yet.