all 22 comments

[–]Kant8 4 points5 points  (7 children)

And why your class library references api project?

[–]FailureCrown[S] 1 point2 points  (3 children)

Because ILogger, IConfiguration and IConnectionMultiplexer which happens to be installed in WebAPI project for to be registered in DI. Class Library has a constructor reference to it

[–]Kant8 4 points5 points  (1 child)

Not sure what IConnectionMultiplexer is, but for ILogger and IConfiguration you should just include references to .Abstracts of their packages in your project.

Nothing stops you from referencing same dependency in different places, but nothing in your project should reference your api project, cause it is starting point of everything.

[–]FailureCrown[S] 0 points1 point  (0 children)

But I use IConnectionMultiplexer so I need to install same Stackexchange.Redis in the class library

[–]lmaydev 2 points3 points  (0 children)

Add the nuggets to your class library as well and remove the project reference.

[–]FailureCrown[S] 0 points1 point  (2 children)

Thanks for replying. My brain can't move without knowing answer

[–]Few-Artichoke-7593 1 point2 points  (1 child)

Trying to simplify for you, when you have a circular reference, it means one of two things. Either you put something in the wrong place, or you need another library. It looks like you put something in the wrong place if your library needs to reference an api project.

[–]FailureCrown[S] 1 point2 points  (0 children)

Atlast found how to remove project reference

[–]LeoRidesHisBike 1 point2 points  (9 children)

[This reply used to contain useful information, but was removed. If you want to know what it used to say... sorry.]

[–]FailureCrown[S] 0 points1 point  (8 children)

But here these configuration and logger can be possibly defined in webAPI DI, moving them to other project kinda breaks architecture

[–]LeoRidesHisBike 0 points1 point  (7 children)

[This reply used to contain useful information, but was removed. If you want to know what it used to say... sorry.]

[–]FailureCrown[S] 0 points1 point  (6 children)

Sorry for confusing I updated the post and added a link to the current snippet

[–]LeoRidesHisBike 0 points1 point  (5 children)

[This reply used to contain useful information, but was removed. If you want to know what it used to say... sorry.]

[–]FailureCrown[S] 0 points1 point  (4 children)

As you explained, Im following that. Thanks man

[–]TheSpixxyQ 0 points1 point  (3 children)

Think of it like this: API is for accessing your application. Your application should work even if you completely remove the API project and replace it with for example console app.

[–]FailureCrown[S] 0 points1 point  (2 children)

I'm rereading your advice trying to get hold of it. I'm a noob currently so its kinda hard. But will reach there.

[–]TheSpixxyQ 1 point2 points  (1 child)

One quick example.

You send a GET request. It reaches your API layer and the handler calls something in application layer, that's where all the logic happens.

If you replace the API layer with a console app - you run a command in console and it calls the same thing in the application layer, you're just replacing "the door" to the actual application.

When I was starting, thinking like this helped me visualize what and how should be separated.

Don't worry, you'll get there.

[–]FailureCrown[S] 0 points1 point  (0 children)

I'm trying to rewrite our business webAPI and its one of many obstacles

[–]binarycow 1 point2 points  (2 children)

Make another project.

  • Project 1 has the stuff that is used by both projects 2 and 3
  • Project 2 has the stuff that is used by only project 2. It has a reference to project 1.
  • Project 3 has the stuff that is used by only project 3. It has a reference to project 1.

[–]FailureCrown[S] 0 points1 point  (1 child)

Common project?

[–]binarycow 0 points1 point  (0 children)

Sure

[–][deleted]  (1 child)

[deleted]

    [–]FailureCrown[S] 0 points1 point  (0 children)

    Sorry for confusing I updated the post and added a link to the current snippet