Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 878881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:50:11+00:00 2026-05-15T11:50:11+00:00

I’m trying to follow the tutorial found here to implement a service layer in

  • 0

I’m trying to follow the tutorial found here to implement a service layer in my MVC application. What I can’t figure out is how to wire it all up.

here’s what I have so far.

IUserRepository.vb

Namespace Data
    Public Interface IUserRepository
        Sub AddUser(ByVal openid As String)
        Sub UpdateUser(ByVal id As Integer, ByVal about As String, ByVal birthdate As DateTime, ByVal openid As String, ByVal regionid As Integer, ByVal username As String, ByVal website As String)
        Sub UpdateUserReputation(ByVal id As Integer, ByVal AmountOfReputation As Integer)
        Sub DeleteUser(ByVal id As Integer)
        Function GetAllUsers() As IList(Of User)
        Function GetUserByID(ByVal id As Integer) As User
        Function GetUserByOpenID(ByVal openid As String) As User
    End Interface
End Namespace

UserRepository.vb

Namespace Data
    Public Class UserRepository : Implements IUserRepository
        Private dc As DataDataContext
        Public Sub New()
            dc = New DataDataContext
        End Sub
#Region "IUserRepository Members"

        Public Sub AddUser(ByVal openid As String) Implements IUserRepository.AddUser
            Dim user = New User
            user.LastSeen = DateTime.Now
            user.MemberSince = DateTime.Now
            user.OpenID = openid
            user.Reputation = 0
            user.UserName = String.Empty

            dc.Users.InsertOnSubmit(user)
            dc.SubmitChanges()
        End Sub

        Public Sub UpdateUser(ByVal id As Integer, ByVal about As String, ByVal birthdate As Date, ByVal openid As String, ByVal regionid As Integer, ByVal username As String, ByVal website As String) Implements IUserRepository.UpdateUser
            Dim user = (From u In dc.Users
                Where u.ID = id
                Select u).Single

            user.About = about
            user.BirthDate = birthdate
            user.LastSeen = DateTime.Now
            user.OpenID = openid
            user.RegionID = regionid
            user.UserName = username
            user.WebSite = website

            dc.SubmitChanges()
        End Sub

        Public Sub UpdateUserReputation(ByVal id As Integer, ByVal AmountOfReputation As Integer) Implements IUserRepository.UpdateUserReputation
            Dim user = (From u In dc.Users
                        Where u.ID = id
                        Select u).FirstOrDefault

            ''# Simply take the current reputation from the select statement
            ''# and add the proper "AmountOfReputation"
            user.Reputation = user.Reputation + AmountOfReputation
            dc.SubmitChanges()
        End Sub

        Public Sub DeleteUser(ByVal id As Integer) Implements IUserRepository.DeleteUser
            Dim user = (From u In dc.Users
                       Where u.ID = id
                       Select u).FirstOrDefault
            dc.Users.DeleteOnSubmit(user)
            dc.SubmitChanges()
        End Sub

        Public Function GetAllUsers() As System.Collections.Generic.IList(Of User) Implements IUserRepository.GetAllUsers
            Dim users = From u In dc.Users
                        Select u
            Return users.ToList
        End Function

        Public Function GetUserByID(ByVal id As Integer) As User Implements IUserRepository.GetUserByID
            Dim user = (From u In dc.Users
                       Where u.ID = id
                       Select u).FirstOrDefault
            Return user
        End Function

        Public Function GetUserByOpenID(ByVal openid As String) As User Implements IUserRepository.GetUserByOpenID
            Dim user = (From u In dc.Users
                       Where u.OpenID = openid
                       Select u).FirstOrDefault
            Return user
        End Function
#End Region
    End Class
End Namespace

IUserService.vb

Namespace Data
    Interface IUserService

    End Interface
End Namespace

UserService.vb

Namespace Data
    Public Class UserService : Implements IUserService

        Private _ValidationDictionary As IValidationDictionary
        Private _repository As IUserRepository

        Public Sub New(ByVal validationDictionary As IValidationDictionary, ByVal repository As IUserRepository)
            _ValidationDictionary = validationDictionary
            _repository = repository
        End Sub

        Protected Function ValidateUser(ByVal UserToValidate As User) As Boolean
            Dim isValid As Boolean = True


            If UserToValidate.OpenID.Trim().Length = 0 Then
                _ValidationDictionary.AddError("OpenID", "OpenID is Required")
                isValid = False
            End If
            If UserToValidate.MemberSince = Nothing Then
                _ValidationDictionary.AddError("MemberSince", "MemberSince is Required")
                isValid = False
            End If
            If UserToValidate.LastSeen = Nothing Then
                _ValidationDictionary.AddError("LastSeen", "LastSeen is Required")
                isValid = False
            End If
            If UserToValidate.Reputation = Nothing Then
                _ValidationDictionary.AddError("Reputation", "Reputation is Required")
                isValid = False
            End If


            Return isValid
        End Function

    End Class
End Namespace

I have also wired up the IValidationDictionary.vb and the ModelStateWrapper.vb as described in the article above.

What I’m having a problem with is actually implementing it in my controller. My controller looks something like this.

Public Class UsersController : Inherits BaseController
    Private UserService As Data.IUserService

    Public Sub New()
        UserService = New Data.UserService(New Data.ModelStateWrapper(Me.ModelState), New Data.UserRepository)
    End Sub

    Public Sub New(ByVal service As Data.IUserService)
        UserService = service
    End Sub

    ....
End Class

however on the line that says Public Sub New(ByVal service As Data.IUserService) I’m getting an error

‘service’ cannot expose type ‘Data.IUserService’ outside the project through class ‘UsersController’

So my question is TWO PARTS

  1. How can I properly implement a Service Layer in my application using the concepts from that article?
  2. Should there be any content within my IUserService.vb?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:50:12+00:00Added an answer on May 15, 2026 at 11:50 am

    Try drawing up a picture in your mind of the following design pattern.

    Your Controller ---(uses) ----> IUserService 
    
    IUserService ----- (uses) ------> IUserRepository
    

    Your controller does not care about the actual implementation (i.e the UserService class) nor your UserService class of the actual repository class.

    For the record, The design pattern is Service Interface Pattern

    Having said all these, you have two problems to fix this:-

    • First, your IUserService should
      declare some operation contracts
    • Second, declare your IUserService as public

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.