Today I ran into an interesting "problem" with Visual Studio .NET 2005 Beta 2. First a little background.
I use a
factory method pattern in order to satisfy a requirement of having a
database agnostic business layer. This is similar, to the
Petshop example on MSDN. So, the code looks something like this...
using
System;
namespace
Example {
interface IDataAccess {
void Delete(int
Id);
}
//Created with Assembly.Load()
class LateBoundDal : IDataAccess {
public void
Delete(int Id) {
Console.WriteLine("Hi, I'm deleting something in a specific
database...");
}
}
class ReferencedDAL {
public void
DeleteSomething(int Id) {
//Assembly.Load goes here to load the
concrete DAL at runtime...
//Activator used for example only!
IDataAccess dalInstance = (IDataAccess)
Activator.CreateInstance(typeof(LateBoundDal));
dalInstance.Delete(Id);d);d);
}
}
class App {
[STAThread]
static void
Main(string[] args) {
ReferencedDAL dal = new
ReferencedDAL();
dal.DeleteSomething(999);
}
}
}
Pretty Simple. But, in order for
Assembly.Load to work, I've placed it (the concrete DAL) in the Bin folder
of the application (in this case a Web app). In Visual Studio 2003, the
Web developers only have a reference to a Common assembly and the BusinessLogic
component. This works great. Without them violating the layered design by
explicitly setting a reference, there's no way for them to code against the
concrete DAL. This is exactly what I want.
But...
In Visual Studio 2005, any class library assembly I place in the Bin folder
automatically gets referenced by the Web application! Why? This is bad news IMO.
I want the junior devs to only code against Common and BusinessLogic, but if
the DAL, ConcreteDAL, etc are in the bin folder, they could just as easily
violate the architecture either purposely or not. Please feel free to drop me a
line if you have an idea as to what I'm missing with VS2005 Beta 2, or if you
have a workaround / solution.