Henrik Elkjær Hagen - 482 - Feb 20, 2014

I have a solution with multiple projects. One of the projects is a web service and another is a desktop application. They both access the same database. Now I have 2 sets of entity classes and two sets of repository classes. The web service set uses OrmLite and the set used by the desktop application is some homemade stuff :). I was wondering if it would be a good idea to share entity and repository classes between the two projects and if so how? I guess have to use some kind of dependency injection in my desktop application to be able to use the repository classes created for the web service. Any pointers, hints, to get me going?

Hi Henrik, it’s unclear what the issue is without seeing concrete examples. I don’t see why you can’t just use the existing classes as-is, or why you would need to use dependency injection. Everything should just be normal c# classes you can manually inject yourself if you want to. 

I believe these types of guidance questions are best asked on StackOverflow with example source code so we can see exactly what the issue is to be able to figure out what answer is expected.

Henrik Elkjær Hagen:

Ok, I guess I was a bit vague. I’ll try to break it down into smaller issues, one of which is this:
I moved some of my DTO’s to a separate assembly. My services was still working fine. But then I tried to move a DTO which is rendered in a razor ViewPage. Then I got a NullReferenceException from Razor/ViewPage.cs. I have changed the reference to the DTO everywhere I can think of, including the .cshtml file. Just by moving this single DTO all my of my services disappeared from the metadata page.

It’s really hard to guess what’s happening based on your description. Is the DTO being referenced int the AppHost contructor and moving the DTO changes where you’re telling ServiceStack all the services are it should wire up?

Henrik Elkjær Hagen:

The problem was that my DTO project was created as a “Class library” and thus had default output directory set to /bin/Debug. While my web service project had /bin as an output folder. Everything worked as expected when I set the output folder of my DTO project to /bin.