![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Q re ReadOnly Properties, Inheritance and IOC Containers Hi I was struggling to find a suitable place to ask this question, so if it is not appropriate here and someone can suggest somewhere else please do. My question is concerning IOC containers and Dependency Injection. The scenarios I'm struggling to get my head around is with regard to a) ReadOnly properties. b) Inheritence AIUI, dependency injection is done via setters or at construction. Now if it is done via setters, then how are you meant to set the value of a readonly property. However, if it is done via construction, I'm struggling to see how inheritence fits in. The situation I face is that I am getting data from a DB and I want to instantiate a business object. The (effectively meta-)data (from the db) tells me what sort of business object I need to instantiate. However, all the business objects share a common base object. At the moment, the intelligence as to how to populate these classes is held within them. I don't think that is correct and am looking move this functionality into a factory (and perhaps in due course an IOC container) responsible for instantiating these objects. However, suppose the base class has a readonly property. If the factory is going to populate the object, how should it populate the readonly base class property. Obviously the factory isn't part of the inheritance chain so having a Protected setter wouldn't work. I could have a friend setter but then any other object in the assembly could potentially set the value so I don't really want to expose this value at all. I had worked up a reflection-based way of doing this and was setting the field values via reflection, but that just "didn't seem right" and I wondered whether it may be slow as well. So I'm sure I must be thinking about this in the wrong way. Any thoughts would be welcome. Thanks S |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| bug in copy-item of readonly files | PowerShell | |||
| RE: ReadOnly | Vista networking & sharing | |||
| setting a variable as readonly | PowerShell | |||