Categories: Open RIA Services, Project Lead, General
We are still waiting for the code to be released by Microsoft, but in the meantime I thought I would post up an extremly preliminary idea of what the DomainController might look like. In this case, it is the DbDomainController:
public
class
AddressBookDomainController : DbDomainController<AddressBookContext>
{
protected
override
void
OnDomainCreating(DbDomainBuilder<AddressBookContext> domainBuilder)
{
domainBuilder.Repositories.Add<AddressRepository>()
.RequiresRole(OperationType.All,
"AddressEditor"
)
.RequiresRole(OperationType.Read,
"ContactViewer"
);
domainBuilder.Repositories.Add<PersonRepository>()
.RequiresRole(OperationType.All,
"PersonEditor"
)
.RequiresRole(OperationType.Read,
"ContactViewer"
);
}
}
The DomainController
can look just like the DomainService does with all of the individual CRUD methods in the body, but you will also be able to register repositories with the DomainController and have the CRUD methods picked up from the repository. This is what the repository would look like:
public
class
PersonRepository
{
AddressBookContext Context {
get
;
set
;}
public
PersonRepository(AddressBookContext context)
{
Context = context;
}
public
IQueryable<Person> GetPeople
{
return
Context.Persons;
}
public
void
InsertPerson(Person entity)
{
DbEntityEntry<LoadRating> entityEntry =
this
.Context.Entry(entity);
if
((entityEntry.State != EntityState.Detached))
{
entityEntry.State = EntityState.Added;
}
else
{
this
.Context.People.Add(entity);
}
}
public
void
UpdatePerson(Person currentPerson)
{
this
.Context.People.AttachAsModified(currentPerson,
this
.Context);
}
public
void
DeletePerson(Person entity)
{
DbEntityEntry<Person> entityEntry =
this
.Context.Entry(entity);
if
((entityEntry.State != EntityState.Detached))
{
entityEntry.State = EntityState.Deleted;
}
else
{
this
.Context.People.Attach(entity);
this
.Context.People.Remove(entity);
}
}
}
This content has not been rated yet.