Results 1 to 3 of 3

Thread: About lazy-init

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Posts
    15

    Default About lazy-init

    Hi all! Excuse me if my question is very simple, but I need to understand...

    Hi I understand, properties of objects, which I defined in xml, will be instantiated only when I address to them? And to suppress this I need to indicate lazy-init=false ?

    Thaks

  2. #2
    Join Date
    Sep 2004
    Location
    Leeds, UK
    Posts
    166

    Default

    Hi Dmitrij

    Not exactly... the 'lazy-init' attribute controls the lazy instantiation of top level objects inside the IoC container at startup.

    If you have an object definition that has its lazy-init attribute set to 'true', then the object defined by that object definition will not be created (instantiated) by the IoC container when the container itself is first loaded. If the value of the lazy-init attribute is set to 'false' (the default), then the object will be instantiated by the container as soon as it starts up.

    The properties of objects are not lazily instantiated. Consider the following object definitions...

    Code:
    <objects>
        <object id="foo" type="..." lazy-init="true"/>
    
        <object id="bar" type="..." lazy-init="false">
            <property name="foo" ref="foo"/>
        </object>
    </objects>
    You can see that the 'foo' object definition is marked as 'lazy-init="true"', and that the 'bar' object definition is not. When the container loads, it will skip the instantiation of the object described by the 'foo' object definition, but when it comes to the 'bar' object definition, it will attempt to instantiate it. Instantiating the object described by the 'bar' object definition means resolving and and thus instantiating all of its dependencies... in this case, this is the 'foo' object, which will be instantiated because the 'bar' object needs it.

    So in answer to what I think was the thrust of your post, no, you cannot have lazily intialized properties... only lazily initialized top level objects. This is not to say that you just plain cannot have lazily initialized properties... just that the Spring.NET libraries don't support this feature straight out of the box. I daresay one could trivially implement the lazy loading of properties using AOP... one to consider for the future I guess.

    Ciao
    Rick

    Darn... I have just noticed that the reference documentation does not describe the lazy initialization of objects at all! I'll fix this for the forthcoming release... thank goodness you posted.
    Senior Consultant, Interface21 - Spring Services from the Source

    The Spring Experience - The Premier Spring Event of 2006. December 7-10, 2006, Hollywood, Florida

  3. #3
    Mark Pollack is offline Spring.NET Co-Lead Spring TeamSpring User
    Join Date
    Sep 2004
    Location
    New York, NY
    Posts
    1,683

    Default

    Hi,

    Added a paragraph about lazy-init in the docs.

    - Mark

Similar Threads

  1. Lazy load support in ASP.Net
    By Aleksei Kachanov in forum Web
    Replies: 5
    Last Post: 06-14-2006, 11:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •