servicestackservicestack-autoquery

How to manage separation of concerns when using ServiceStack AutoQuery


I am having some issues with how to organise my AutoQuery code. My project structure currently looks like:

/Project
/Project.ServiceInterface
  Service.cs
/Project.Logic
  Manager.cs
  /Types
    DbModel.cs
/Project.ServiceModel
  Request.cs
  /Types
    DtoModel.cs

With this setup, the ServiceModel has no knowledge of the Logic models. Because of this, I can't make a request query like QueryDb<DbModel, DtoModel> without essentially duplicating all my DbModel objects in my ServiceModel or adding a dependency to Logic in ServiceModel. I also have custom AutoQuery service implementations and inside those I want to be able to leverage code that has been written using my DbModels elsewhere.

Does anyone have any recommendations or relevant examples? I feel like I'm approaching this problem incorrectly and making it more complex than need be. Thanks.


Solution

  • Auto Query lets you create Services by defining a Request DTO as such all Types it references must also be the ServiceModel Assembly, so you'd either need to move the Data Models your AutoQuery Services references to your ServiceModel project or annotate your DTO so that it can be used by OrmLite to query your RDBMS Table where it can use the [Alias] attribute where names differ and the [Ignore*] attributes depending on whether the property should exist in OrmLite or Serialization, e.g:

    [Alias("MyTable")]
    public class MyDto
    {
        [Alias("DbName")]
        public string DtoName { get; set; }
    
        [Ignore] 
        public string IgnoredInOrmLite { get; set; }
    
        [IgnoreDataMember] 
        public string IgnoredInSerialization { get; set; }
    }
    

    Otherwise you're not going to be able to use Auto Query and would need to create Custom Services whose internal implementation makes use of your Data Models where they're hidden from your public Services Contract.

    Personally I'd recommend moving the Data Models you need to your ServiceModel Assembly (that continues to use the same Namespace as your other DataModels) as OrmLite DataModels are POCOs that like DTOs typically don't need any additional references other than the impl-free ServiceStack.Interfaces.