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
Accuses Readonly for a property that is not ReadOnly #113
Comments
This clearly tells you that you have a leaky abstraction in your Domain Model. A Domain Model should not be designed with any particular boundary technology in mind. This particular issue is very clearly telling you that your Domain Model is not reusable.
The best course of action is to reconsider your API design. Normally, I'd do something like this: public class Telefone : IEntity
{
public Telefone(int id)
{
this.Id = id;
}
public virtual int Id { get; private set; }
public virtual string Tipo { get; set; }
public virtual string Numero { get; set; }
} |
This generated a lot of discussion in a group of architecture that I follow.
|
Agreed that these are all problems. All four of them strongly indicate that the Domain Model depends on the persistence layer, and can't be made to work without it.
|
I understand the problem. I can not change the PKs type to Guid, would really work. I understand now that the problem is not related to AutoFixture, but if you're interested. I create a sample project to discuss this. thanks. |
In my domain layer have the class:
The Id is protected internal. This is deliberate, who generates the Id is the database and should be ReadOnly.
But in the test layer, must have access to the setter of this property.
So in my domain layer added the attribute in AssemblyInfo.cs:
[assembly: InternalsVisibleTo("MyTestLayer")]
This will allow me to set the Id in tests layer but not in the domain layer!
In test layer
new Telefone().Id = 1; // Works!!
In UI layer
new Telefone().Id = 1; // Not compile! Not works!
Problem
Theoretically, the above code should work, but when my road test an error occurs:
All properties
Id
s areprotected internal
.In the same file, same test can do something like:
new Telefone().Id = 1; // Works!!
new Email().Id = 1; // Works!!
The text was updated successfully, but these errors were encountered: