I have had a dig around for an answer to this issue but everything previously asked seems to be a complex variation on this and doesn't answer the question so I thought I should just ask.
I am developing a three tier application with the following.....
I have created an Entity Framework model, repository classes and my connection string is in the DAL App.Config file. I have now created my first class in the BLL and it references the DAL. When trying to test the following, very basic method I get an error relating to a missing connection string in the BLL.
public static List<DAL.Item> getItems() {
List<DAL.Item> result = new List<Item>();
DAL.Repositories.ItemRepository myRepository = new DAL.Repositories.ItemRepository();
result = myRepository.GetAll().ToList();
return result;
}
Why is the BLL looking for the connection string? Am I missing something really obvious here?
If I need to include the connection string across multiple layers, which defeats the purpose of the n-tier structure, then how is the best way to do this? Can anyone shed some light on this for me?
You are new-ing up an instance of the DAL which in turn will try to look at your configuration file (not found due to the scope being in the Business Layer / Unit Test. What you should do is look into Inversion Of Control (IoC) and inject the DAL into the Business Logic Layer. Then you can mock out your DAL that won't try and actually hit the config file / database etc.