Before ASP.Net Core:
I create a MVC site and two class libraries in one solution. Let's say the project names are MVC, Lib1 and Lib2.
I add references as follows: MVC references Lib1, Lib1 references Lib2.
With this reference structure, MVC cannot access classes in the Lib2 project, which is as expected and what I want.
The same project and reference structure in ASP.Net Core: MVC can access classes in Lib2. Looking at the MVC/References node in the Solution Explorer in Visual studio, you can see MVC/References/DNX 4.5.1/Lib1 - so far so good (I did add a reference to Lib1 from MVC) - but then I can expand the Lib1 node, and will see Lib2 under it. End result: MVC can access Lib2 classes via a reference chain.
I presume this behaviour is by design, but then how can I achieve the old behaviour? I do not want developers to be able to access Lib2 classes from MVC.
Yeah, this is now a feature in .NET Core. Read more from this SO answer.
BUT you can hide Lib2 from your MVC csproj using PrivateAssets attribute on your ProjectReference:
in your Lib1.csproj:
<ItemGroup>
<ProjectReference Include="..\Lib2.csproj" PrivateAssets="All" />
</ItemGroup>
This way, when the MVC.csproj is referencing Lib1, it won't be able to see any Lib2 class because you hid it in your Lib1.csproj.
Related
I have my project containing most of my functions (MainProject).
I want to have a web service referencing MainProject and use some of those functions.
However I want to add conditionnal compilation in MainProject to not include all the functions and only build them if a webservice project is needing them.
I added one function like this:
#if WEBSERVICE
public void MyApi()
{
}
#endif
And in the project settings of my web service I tried adding a define constants:
<ProjectReference Include="..\..\api\MyAPIs.csproj">
<Project>{ed6ba855-7082-4b28-99a2-3e9fcf810433}</Project>
<Name>API</Name>
<DefineConstants>WEBSERVICE</DefineConstants>
</ProjectReference>
My goal is to add the force the WEBSERVICE symbol to be added when building my web service project.
This doesn't work, when I check the build output my symbol is not added when building the dll for the project.
I know I could add a build configuration to solve that issue but since I will have several webservice projects I would rather keep my build configurations small and just add an extra symbol when needed.
I have also added my WEBSERVICE symbol in each configuration of my Webservice Project
<DefineConstants>$(DefineConstants);SERVICE_BOT</DefineConstants>
Is what I'm trying to achieve possible?
I have a .NET class library project that targets UWP applications. I wish to re-purpose it to also support Xamarin.Forms applications.
Initially, I imagined that I could achieve this by creating a new .csproj file, in the same directory as the original, and configure it to reference the same set of source files, but with a different set of dependencies, as appropriate to the target framework.
However, this doesn't seem possible, since each of the projects expects its dependencies to be defined in a project.json file that resides in the project directory. If it were permissible to rename project.json to a framework-specific name, that would solve the problem. But, as far as I can see, the name and the location of project.json is fixed.
Is there a recommended way of creating multiple projects that reference the same codebase, but with different dependencies?
I am wondering if there is a server side MVC framework, in any language which supports creating Sub-projects.
For example something like this:
-Root project
|-- Project A
|-- Project B
|-- Project C
|-Root project files (such as route list, config files and etc...)
Each Sub-project and the Root project have the same structure.
Note that this is just an example, any other structure is fine, as long as it is MVC and supports sub-projects.
You can use ASP.NET MVC. The AREA feature is pretty much what you are describing.
http://www.itorian.com/2013/10/area-in-mvc-5-with-example-step-by-step.html
https://mvcmusicstore.codeplex.com/
I'm trying to build a project structure like this:
Project
|--Web_module.war
|--Data_module.jar(Spring)
|--Util_module.jar
|--other public api...
which means, different modules should be packed into different jars, so i have to have more spring configurations(application-context.xml) for different modules (e.g. for data module and for web module).
My question, how could I organize all the configuration files to include them correctly in the web module.
Thanks in advance.
Plan to have a single eclipse project for each jar file that you anticipate.
Choose the jars files / eclipse projects as per your project functionality to be modular and self contained, as far as possible.
Use junit tests in each eclipse project to thoroughly test individual projects/modules, using spring unit test support
Each eclipse project will contain its own spring config context file eg Util_module project might contain a util-context.xml
Finally have an eclipse dynamic web project as a wrapper web application which will aggregate all your "module" projects
UI artifacts like HTML, JS, JSPs, etc plus java code which uses web application contexts like controllers, servlet filters etc should be included in the eclipse web project
In the eclipse web project's java build path, but the module "projects" as "required" projects
In the eclipse web project's deployment assembly, add module "projects" as dependencies.
now when you build-all and deploy the web app, all depending module projects will compile and deploy as well, but more importantly, all project functionality will be divided into seperate modular projects
setup dependencies between projects with care, so as not to introduce cyclic dependencies
dont be afraid to refactor project structure when needed to maintain clean and relevant modules
For your modules to publish their own configuration (and your main application to detect them automatically), you can, in your main applicationContext.xml, import other context.xml files from the classpath using a pattern with wildcards :
<import resource="classpath*:conf/moduleContext.xml" />
This tells spring to find and read files in all jars that match conf/moduleContext.xml.
Note there is a little limitation to this : you must have your context files in at least one directory (not in the root of the classpath). This is why in my example you have de "conf" directory.
I'm using Castle Windsor to do some dependency injection, specifically I've abstracted the DAL layer to interfaces that are now being loaded by DI.
Once the project is developed & deployed all the .bin files will be in the same location, but for while I'm developing in Visual Studio, the only ways I can see of getting the dependency injected project's .bin file into the startup project's bin folder is to either have a post-build event that copies it in, or to put in a manual reference to the DAL project to pull the file in.
I'm not totally thrilled with either solution, so I was wondering if there was a 'standard' way of solving this problem?
Could you set the build output path of the concrete DAL project to be the bin folder of the dependent project?
Mike: Didn't think of that, that could work, have to remember to turn off copy-local for any libraries / projects that are common between them