Circular dependency error between projects

M

mickieparis

Hello, I’m working on my first n-tier project. I have a ui tier,
business layer tier and a data access tire. I created a custom
exception class in my bl tier but I’d like to use this class in my
other tiers. However, you can’t have cross-reference projects or you
get a circular reference error. So, in n-tier projects how do most
handle custom error classes. Do you create a separate project (class
library) just for error handling? And add reference to this project
from all the other projects?

Thanks.
MP
 
P

Peter Duniho

mickieparis said:
Hello, I’m working on my first n-tier project. I have a ui tier,
business layer tier and a data access tire. I created a custom
exception class in my bl tier but I’d like to use this class in my
other tiers. However, you can’t have cross-reference projects or you
get a circular reference error. So, in n-tier projects how do most
handle custom error classes. Do you create a separate project (class
library) just for error handling? And add reference to this project
from all the other projects?

That's one way I would do it, for exceptions that are broadly useful
across all tiers. These would be in the form of a utility assembly that
has no specific tier it goes with.

An alternative would be to design the class relationships so that the
exceptions are declared in the tier where they are created. Different
tiers may declare different exceptions.

Since a lower-level tier should not be special-casing exceptions from
higher-level tiers anyway, doing it that way should be fine. You won't
need to refer to a type found in a higher-level tier from a lower-level
one (which is true of types found in each tier, even regardless of this
specific custom exception/error example).

Pete
 
T

Tom Shelton

Hello, I?m working on my first n-tier project. I have a ui tier,
business layer tier and a data access tire. I created a custom
exception class in my bl tier but I?d like to use this class in my
other tiers. However, you can?t have cross-reference projects or you
get a circular reference error. So, in n-tier projects how do most
handle custom error classes. Do you create a separate project (class
library) just for error handling? And add reference to this project
from all the other projects?

Thanks.
MP

Generally, for things DTO's and globaly useful objects, I put them in another
project - essentially, I usually will create a Data Object layer that will be
referenced from all of the other layers.
 
A

Arne Vajhøj

Hello, I’m working on my first n-tier project. I have a ui tier,
business layer tier and a data access tire. I created a custom
exception class in my bl tier but I’d like to use this class in my
other tiers. However, you can’t have cross-reference projects or you
get a circular reference error. So, in n-tier projects how do most
handle custom error classes. Do you create a separate project (class
library) just for error handling? And add reference to this project
from all the other projects?

First terminology.

I consider it most logical to use tiers
for what can but not necessarily is separated on
different physical boxes and layers for what is just
a logical separation within a tier. So you have have
a 3 tier solution with web browser + your ASP.NET web app +
a SQLServer and have the ASP.NET web app divided in 3 layers:
PL, BLL and DAL.

Note that many including some MS docs uses tiers and layers
as synonyms.

Back to substance.

You can create a separate project with some global accessible
classes (DTO's, exceptions etc.). It may even be the fastest
solution, but I don't think it is optimal design. It tend
to couple the layers.

To really decouple the layers, then you should use
a model:
* a layers only public top level types is
- a factory class
- a bunch of interfaces
- some DTO classes
- some exception classes
- some enums
* a layer is only dependent on the layer below it, not
on layers above it and not on some global accessible
code
* the implementation of a layer is selected by the layer
above it via configuration (like Spring.NET)
* exceptions from the layer below is not passed on
to the layer above

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top