1

I'm developing a project, ultimately it is going to be a web app. But I'm trying to follow a sort of layered approach for the business objects and data access, i've created the following class library projects in a single blank solution:

MyCompany.MyProject.Repository
MyCompany.MyProject.Model
MyCompany.MyProject.Service

MyCompany.MyProject.Repository has a reference to MyCompany.MyProject.Model MyCompany.MyProject.Service has a reference to MyCompany.MyProject.Model and MyCompany.MyProject.Repository.

This little framework of mine is going to be used by multiple applications in the future and so I am creating them seperately to the web app.

I have two questions:

  1. With regards to layering the app is this approach correct, the web app (Or any app that needs to use my framework) will need to have all three DLL's in it's Bin directory - am I understanding this correctly?

  2. The MyCompany.MyProject.Model project holds all of my business objects. With regards to encapsulation - for example I have a Customer object:

    Public Class Customer

    Private _customerID As Int32

    Public Property CustomerID() As Int32 Get Return _customerID End Get Friend Set(ByVal value As Int32) _customerID = value End Set End Property

    End Class

This is the way I think that the ID for the customer object should be exposed, because of the Friend access modifier on the Set the ID for the customer should only be able to be set internally by the framework, and only read externally by the web app or any other app created in the future. But because my code is in seperate class library projects, the MyCompany.MyProject.Repository for example cannot access it even though my Namespaces follow suit.

This doesn't seem to fit my understanding of encapsulation, what am I doing wrong here?

Your help is much appreciated.

Thank you.

Tickles
  • 11
  • 2

1 Answers1

0

The scenario you discribed is relatively common. I prefer using friend assemblies in this case. They allow acessing internal(.net) or friend (VB) members. You can find more info about friend assemples here.

Hope it helps!

Maksym Strukov
  • 2,679
  • 1
  • 13
  • 17