Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

References between Projects independence #12

Open
hongquan09dth5 opened this issue Jul 26, 2021 · 3 comments
Open

References between Projects independence #12

hongquan09dth5 opened this issue Jul 26, 2021 · 3 comments

Comments

@hongquan09dth5
Copy link

Hi Neil,

First of all, I'm so naive about dotnetcore, I just was into it for one month.

My problem was I've seen you only added Infrastructure project references into API project. It means API only depends on Infrastructure, but what am I seeing that you were able to use the Core project's functionality or models on API project.

For example, In BasketController, you addded:

using Core.Entities;
using Core.Interfaces;

It's too weird, because I was not able to do it as well as you did.

I've checked your API.csproj and maked sure you only added Infrasctructure references and it exactly was:

your API.csproj

<ItemGroup>
    <ProjectReference Include="..\Infrastructure\Infrastructure.csproj"/>
  </ItemGroup>

I only can do the same thing if I did add Core references into API project as well:

my API.csproj

 <ItemGroup>
    <ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
    <ProjectReference Include="..\Core\Core.csproj" />
  </ItemGroup>

I ignored the issue for this Section 3, but I did notice it again as studying in Section 13 during I tried to setup the connection string for Redis in Startup.cs. I was not able to print up the StackExchange.Redis, because in previous step you just added the Redis package in Infrastructure project but API porject. it's big surprised again for me, how can you use the Redis namespace in API project :

Startup.cs

using StackExchange.Redis;

but I got the error when I added this namespace. It only worked if I must to install package in both API and Infrastructure.

Did I setup something incorrectly?

Here are my dotnet information:

`
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.301\

Host (useful for support):
Version: 5.0.7
Commit: 556582d964

.NET SDKs installed:
5.0.301 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
`

@DanzoLion
Copy link

DanzoLion commented Jul 26, 2021 via email

@hongquan09dth5
Copy link
Author

Core.entities is our own folder and class we made we have access to these throughout via tha navigability references it’s not Microsoft.core

Thanks for replying,

Yes, it's true. Core.entities is your own folder and class you made. What I was going to say was how you were able to type "using Core.entities" in BasketController which is a controller in API project?

The reason why did I ask this question because I didn't see you added the "Core" project references to "API" project

Here is your API project .csproj ( or folder as you said) :

<ItemGroup> <Content Include="Content\**" CopyToPublishDirectory="PreserveNewest" /> <ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> </ItemGroup>

You can see there is only the ProjectReferences for Infrastructure project in API projecct .csproj

When I did the same thing, and type namespace "using Core.entites" in BasketController.

The error said:
the type or namespace name 'Core.entities' could not be found

I was going to fix by adding Core project references to API project as well as I did with Infrastructure.

Here is my API project .csproj :

<ItemGroup> <ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> <ProjectReference Include="..\Core\Core.csproj" /> </ItemGroup>

You can see I've added two ProjectReference in API project.

Then this namespace error was gone.

In Section 3, I heard you said: The Infrastructure has Core references, the API has Infrastructure references.

It's so weird. I've checked all your .csproj, and make sure my all references (Core, API, Infrastructure) are correct. But now my API project need to have both Core references and Infastructure references

So it made me to be confused is am I missing something.

My English is not good, so if I said something too rude or hard to understand, please don't feel upset.

Regards,

@pauldenmeadwebdesigns
Copy link

Make sure your Infrastructure project is referencing the Core project:

<ItemGroup> <ProjectReference Include="..\Core\Core.csproj"/> </ItemGroup>

Everything should then work as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants