Use Fody.EmptyConstructor on a separate project?

119 Views Asked by At

I have a solution with two projects Business and Domain I'm using Fody.EmptyConstructor to create parameterless constructors for my domain models on runtime. It works well when I add the Fody.EmptyConstructor package to the Domain project, but I'd rather not have that as a dependency there and instead have it in Business. Is there a way to do so?

-Sln 
--Domain 
--Business (has reference to Domain) 
---FodyWeavers.xml

FodyWeavers.xml:

<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
  <EmptyConstructor />
</Weavers>

Thanks in regard for any suggestions.

1

There are 1 best solutions below

2
On BEST ANSWER

Fody needs to be installed in the project it modifies, along with its addins. It does not modify projects transitively, nor can it modify another project.

But it won't add a dependency if you add the PrivateAssets="all" attribute to the PackageReference items of Fody and EmptyConstructor.Fody.

Depending on how the weaver is configured, Fody will remove references to the weaver libraries. This is the case for EmptyConstructor.Fody.