Kevin Le - Khnle
Kevin Le - Khnle

Reputation: 10857

Circular DLL dependencies in .NET

I have a DLL which provides an entry point to an ASP.MVC application. Let's call this Primary.DLL. In Primary.DLL, there are LINQ-to-SQL data context and other classes defined. Somewhere in Application_Start(), Assembly.Load() is called to load Secondary.DLL. Secondary is NOT referenced in Primary.DLL's project file. But Primary is referenced in the project file of Secondary.DLL because the LINQ-to-SQL data context and other classes mentioned above are used in Secondary.

Would this create a circular dependency problem? Would there be any problem with this kind of design?

Upvotes: 6

Views: 335

Answers (3)

competent_tech
competent_tech

Reputation: 44941

We do this all of the time with customer-specific customization DLLs. We use the same functionality in web applications, services, and desktop exes.

The customer DLLs reference the base project DLLs so that they can inherit from various classes and implement interfaces. To do so, they must have a reference to the base dll.

At application startup (global.asax Application_Start or an exe's initialization routine), we load any discovered customization DLLs through Assembly.Load and it definitely does not create a cross-reference.

Upvotes: 1

Chris Shain
Chris Shain

Reputation: 51359

It won't create a circular dependency problem, but it may not be a great design. Circular dependencies require an actual reference between two or more projects.

Upvotes: 1

Ethan Cabiac
Ethan Cabiac

Reputation: 4993

Assemblies do not get reloaded into an AppDomain, and you are only loading Secondary.dll within Application_Start so this should not cause any problems and would also not result in any manifestation of a circular dependency.

Upvotes: 1

Related Questions