Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Q re ReadOnly Properties, Inheritance and IOC Containers

Reply
 
Old 09-20-2008   #1 (permalink)
Simon Woods


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46