Ok, so I'm a bit confused as to what is going on with the following data.
We have the following Structure in our application:
Here's our usage: In the controller we call the model located in Portal.Core, which populates by calling Portal.Data, so basically Web can never see data.
Here's the catch: In the controller, say for example I try and instantiate a new DTO object called Client like so:
var client = new Client();
It won't work, which is expected it has no idea what Client is and even specifying a using won't cut it. That's fine.
BUT if I try and do that exact same line in the View, Resharper adds the using to the view and then no complaints, the project runs and we can use DTO classes in our views.
So the question is, why is this? I'm trying to stop our juniors from using DTO classes in Views, so I've purposely removed the reference to the Data project in Web, but they can still use the classes. Can someone shed some light?
I ran the same test with ASPX and Razor views. Referencing Client
in ASPX views fails however in Razor views they work. The views are compiled on the fly when you request the application, so I had a look at some folders in "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\portal.web" and from cmdline files references to the assembly is explicitly added when the view is compiled.
It seems the process that compiles razor views adds references to all the assemblies in the bin folder. However, looking at the source of ASP.NET MVC, I cannot confirm this.
So, the only conclusion I can come to is that it is a side effect of using the Razor View Engine.
That said, you may want to scan the web.config to see if it was included using the assemblies element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With