asp.net mvc - "Cannot Resolve IProjectServices" with Interfaces for Service Layer in MVC -



asp.net mvc - "Cannot Resolve IProjectServices" with Interfaces for Service Layer in MVC -

i'm not sure if i'm doing right. have project called project.services contains bunch of services controllers in mvc application leverage.

in terms of exposing services project web project - have interface defined in web project called "iprojectservices" bunch of blank methods correspond need.

i effort implement interface in services project using syntax

public class projectservices : iprojectservices

i'm getting "cannot resolve iprojectservices" error - before start digging this, using interfaces correctly here?

i'm thinking web project saying "hey need kind of services don't want depend straight on services project i'll create interface" , services project saying "hey no problem i'll implement that, maybe project (like tests) implement differently in future we're not tightly coupled". thinking right?

here illustration implementation using unity. hope helps.

working backward controller...

mvc project: dashboardcontroller.cs

public class dashboardcontroller : controller { private readonly idashboardservice dashboardservice; public dashboardcontroller(idashboardservice dashboardservice) { this.dashboardservice = dashboardservice; } [httpget] public actionresult index() { var model = this.dashboardservice.buildindexviewmodel(); homecoming this.view(model); } }

mvc project: global.asax

public class mvcapplication : system.web.httpapplication { protected void application_start() { // standard mvc setup // ... // application configuration var container = new unitycontainer(); new appname.services.unitybootstrap().configure(container); } }

services project: dashboardservice.cs

public class dashboardservice : idashboardservice { // ctor // ... public indexviewmodel buildindexviewmodel() { var currentperformanceyear = this.repository.getmaxperformanceyear().performanceyearid; var staff = this.repository.getstaffbysamaccountname(this.currentuser.identity.name); var model = new indexviewmodel { staffname = staff.fullname, staffimageurl = staff.staffimageurl, // ... }; homecoming model; } }

services project: idashboardservice.cs

public interface idashboardservice { indexviewmodel buildindexviewmodel(); }

services project: unitybootstrap.cs

public class unitybootstrap : iunitybootstrap { public iunitycontainer configure(iunitycontainer container) { homecoming container.registertype<idashboardservice, dashboardservice>() .registertype<isharepointservice, sharepointservice>() .registertype<istaffservice, staffservice>(); } }

company enterprise library utilities project: iunitybootstrap.cs

public interface iunitybootstrap { iunitycontainer configure(iunitycontainer container); }

asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -