tags:

views:

94

answers:

1

I am new to setting up WCF, I have it going in my project, but I have like 5 different 'services' in my one WCF project and I am wondering if I am doing the right thing. My services for now are 1-1 to my database tables. I end up having something like:

public class Projects : IProjects
{
    public List<Project> GetAll()
    {
        return (from p in Connection.Data.Projects
                select new Project {ID = p.id, Name = p.name}).ToList();
    }

    public Project GetByID(int id)
    {
        return (from p in Connection.Data.Projects
                where p.id == id
                select new Project {ID = p.id, Name = p.name}).First();
    }

    public Project AddProject(string name)
    {
        var project = new Data.Projects {name = name};
        Connection.Data.AddToProjects(project);
        Connection.Data.SaveChanges();

        return new Project {ID = project.id, Name = project.name};
    }

    public void DeleteProject(int id)
    {
        var project = (from p in Connection.Data.Projects
                       where p.id == id
                       select new Project {ID = p.id, Name = p.name}).First();

        Connection.Data.DeleteObject(project);
        Connection.Data.SaveChanges();
    }
}

I have a similar class for each of the tables in my project. Should I be finding a way to use 1 service connection with sub classes or keep it as 1 service class per table?

+2  A: 

"It depends!" :-) The standard answer for all IT and programming questions :-)

I don't see anything wrong with having those 5 separate services - you don't really gain anything by merging them all together into one big service, I'd say. I would prefer to keep them separate and "lean'n'mean".

If you have five separate services, you can also manage things like access permissions to them for each one separately, e.g. let certain user groups use one service, while not another.

Again: I think you're doing it just fine - I don't see any compelling reason or benefit from having one huge services vs. five smaller, nimbler ones.

Come to think of it - the only real change I might suggest is trying to design your services so that they are more closely matched to what your app wants to do (i.e. the operations you expect your app and thus your services to handle), rather than modelling them too closely to the database. Try to think "task-oriented" or in terms of operations, rather than the underlying store where they'll store their data.

Marc

marc_s
awesome, thanks man!
Eric P