Currently I have an ASP.NET project that uses Entity Framework Core for data access. I am using the third party library HotChocolate
to host a GraphQL Server on top of the EF Core data model.
In HotChocolate I can use the Authorize
attribute to control access to the data. E.g. the following entity is only to be accessed with users satisfying a certain policy that is configured during startup. The attribute can apply to either the class level or only to specific properties of the class.
If everything is in one project, this works fine. However, I'd like to separate concerns and move the data logic into a separate class library which I want to reference in the ASP.NET project. But the namespace HotChocolate.Authorization
namespaces required for that the Authorize
attribute lives in the ASP.NET project (which imports the HotChocolate dependency) and not in the class lib in which I'll move the EF Core logic. So I will have to remove that attribute.
Is there a way I can re-add in the ASP.NET layer?
I guess theoretically, I could also import the HotChocolate library also in the class lib for the EF Core model just to have access to its attributes, but somehow I have a feeling that this is not the way it is supposed to be.
Any suggestions are greatly appreciated.
[Authorize(Policy = "some-policy-name")]
public class Organisation
{
public int Id { get; set; }
public string Name { get; set; } = null!;
}