c# - SOA Question: Exposing Entities -
i incorporate soa pattern in 3 tier structure. created service layer (wcf host) between bll , ui. structure setup looks this
ui <> wcf <> bll <> dal
<---[entities] --->
the problem is, have entities in separate dll (and visible in layers except on ui) now, need expose consumer of service can use it.in case, ui. how can possibly that?
entities.dll
namespace entities { public class account { public string acctid { get; set; } public string acctname { get; set; } } }
now, im planning use in wcf
service interface layer
public class accountservice : iaccountservice { public account getaccount(string acctid) { //fetch dal through bll } }
is ok attribute entities? (note, i'm using entities in dal , bll)
using system.runtime.serialization; namespace entities { [datacontract] public class account { [datamember] public string acctid { get; set; } [datamember] public string acctname { get; set; } } }
any suggestion guys?
here's system works us:
you should typically use data transfer object reflects data you're expecting need on client side. business layer should define these dtos, along repository interfaces. data layer should implement repository interfaces, converting data-layer entities dtos. wcf layer should outward-facing wrapper various repository interface methods.
this way, looks more this:
ui ---\ | bll -- dal wcf---/ [ dto ] [repositories] [entities]
in mind, see wcf layer being part of ui layer, i'd feel right having them both aware of objects defined in business layer. however, take 1 step further, , make wcf layer in charge of converting business objects dtos:
ui -- wcf -- bll -- dal [ dtos ] [ repositories ] [ business objects ] [entities]
this way, each layer aware of @ single layer on each side of it. dtos can annotated serialization or whatever, because intended purpose. data-access layer aware of data entities.
in response comment:
if entities defined in data-access layer, not dtos. modeling data layer, doesn't translate directly objects need in ui.
the reason i'm suggesting defining interfaces repositories can use dependency injection loosen coupling between wcf layer , business layer. serve make wcf layer unit-testable, because can create fake or mock repository implementations simulate particular situation.
in first model recommended, wcf methods repository methods, typical wcf "wrap" repository method:
public ienumerable<task> getactivetasks() { return _taskrepository.getactivetasksforuser(_sessionmanager.currentuser); }
Comments
Post a Comment