Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
NH facility: lazy session factory construction
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Germán Schuager  
View profile  
 More options Feb 1 2009, 8:43 am
From: Germán Schuager <gschua...@gmail.com>
Date: Sun, 1 Feb 2009 10:43:54 -0300
Local: Sun, Feb 1 2009 8:43 am
Subject: NH facility: lazy session factory construction

Hi,
I have the following scenario in a Winforms application:

NH facility is configured from app.config with 2 session factories.
One of these configurations needs to get its connection string from data in
the other database.

So, I need a way to initialize just the first session factory, retrieve some
information and modify the configuration of the other factory before it is
built.

I've been thinking that this could be interesting: to add a "lazy" attribute
to the factory configuration and to register a proxy of ISessionFactory in
the container instead of the real session factory. An
SessionFactoryInitializerInterceptor will take care of doing
cfg.BuildSessionFactory() the first time that it is needed. In the
meanwhile, I can modify the conection string doing something like this:

    var cfg = kernel.Resolve<Configuration>("lazySessionFactory.cfg");
    cfg.SetProperty("connection.connection_string", newConnectionString);

What do you think about this? Is there a simple way to achieve this?
If this could be useful I'm willing to submit a patch.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 1 2009, 8:46 am
From: Tuna Toksoz <tehl...@gmail.com>
Date: Sun, 1 Feb 2009 15:46:46 +0200
Local: Sun, Feb 1 2009 8:46 am
Subject: Re: NH facility: lazy session factory construction

This is one of the things i had  in mind-lazy initialization- but for some
reason, it went out of my mind.
I guess everybody could benefit from lazy initialization, and if you'd like
to send a patch, I'd be glad to review it.

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 1 2009, 11:02 am
From: Tuna Toksoz <tehl...@gmail.com>
Date: Sun, 1 Feb 2009 18:02:46 +0200
Local: Sun, Feb 1 2009 11:02 am
Subject: Re: NH facility: lazy session factory construction

I guess all you need is to inherit from ComponentActivator.

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Germán Schuager  
View profile  
 More options Feb 1 2009, 11:09 am
From: Germán Schuager <gschua...@gmail.com>
Date: Sun, 1 Feb 2009 13:09:37 -0300
Local: Sun, Feb 1 2009 11:09 am
Subject: Re: NH facility: lazy session factory construction

I don't think I understand what you mean.

I was thinking in doing something like this:

            ISessionFactory sessionFactory;

            string dontBuild = config.Attributes["lazy"];
            if ("true".Equals(dontBuild))
            {
                ProxyGenerator generator = new ProxyGenerator();
                sessionFactory = (ISessionFactory)
generator.CreateInterfaceProxyWithoutTarget(typeof (ISessionFactory),

new SessionFactoryInitializerInterceptor(cfg));
            }
            else
            {
                sessionFactory = cfg.BuildSessionFactory();
            }

in the ConfigureFactories method of NHibernateFacility.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 1 2009, 11:11 am
From: Tuna Toksoz <tehl...@gmail.com>
Date: Sun, 1 Feb 2009 18:11:34 +0200
Local: Sun, Feb 1 2009 11:11 am
Subject: Re: NH facility: lazy session factory construction

This would also work, but i guess ComponentActivator is a better way, what
do the others think? I am not expert on microkernel.

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 1 2009, 11:15 am
From: Tuna Toksoz <tehl...@gmail.com>
Date: Sun, 1 Feb 2009 18:15:47 +0200
Local: Sun, Feb 1 2009 11:15 am
Subject: Re: NH facility: lazy session factory construction

However, what I said requires some changes to Facility itself, the way
SessionFactories stored requires them to be initialized(or lazy
initialized-as-you-did), component activator thing needs some change.

IF you send me a patch, then I would review & apply then start the work with
componentactivator thing.

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Germán Schuager  
View profile  
 More options Feb 1 2009, 11:43 am
From: Germán Schuager <gschua...@gmail.com>
Date: Sun, 1 Feb 2009 13:43:04 -0300
Local: Sun, Feb 1 2009 11:43 am
Subject: Re: NH facility: lazy session factory construction

Here it is.
Let me know what you think.

  lazysessionfactory.patch
15K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 1 2009, 11:52 am
From: Tuna Toksoz <tehl...@gmail.com>
Date: Sun, 1 Feb 2009 18:52:43 +0200
Local: Sun, Feb 1 2009 11:52 am
Subject: Re: NH facility: lazy session factory construction

Looks good, I guess I will mark lazyness as default.

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 1 2009, 5:55 pm
From: Tuna Toksoz <tehl...@gmail.com>
Date: Mon, 2 Feb 2009 00:55:30 +0200
Local: Sun, Feb 1 2009 5:55 pm
Subject: Re: NH facility: lazy session factory construction

Does anybody know if there is a way to find if a component is initialized
before?

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 1 2009, 6:29 pm
From: Tuna Toksoz <tehl...@gmail.com>
Date: Mon, 2 Feb 2009 01:29:50 +0200
Local: Sun, Feb 1 2009 6:29 pm
Subject: Re: NH facility: lazy session factory construction

I did some reflection to test it, it worked :)

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 1 2009, 6:35 pm
From: Tuna Toksoz <tehl...@gmail.com>
Date: Mon, 2 Feb 2009 01:35:31 +0200
Local: Sun, Feb 1 2009 6:35 pm
Subject: Re: NH facility: lazy session factory construction

German,

Thanks for your efforts, I really appreciate it. I went with
CustomComponentActivator approach and it is available in the trunk.

            var model = new ComponentModel(id, typeof(ISessionFactory),
typeof(Empty));
            model.LifestyleType = LifestyleType.Singleton;
            model.ExtendedProperties[Constants.SessionFactoryConfiguration]
= cfg;
            model.CustomComponentActivator = typeof
(SessionFactoryActivator);
            Kernel.AddCustomComponent( model );
            sessionFactoryResolver.RegisterAliasComponentIdMapping(alias,
id);

I ensured that SesisonFactory is singleton and activated viaa
SessionFactoryActivator.
and in the activator, all I did is that

        public override object Create(CreationContext context)
        {
            var configuration =
Model.ExtendedProperties[Constants.SessionFactoryConfiguration]
                                as Configuration;
            return configuration.BuildSessionFactory();
        }

I hope this helps.

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Germán Schuager  
View profile  
 More options Feb 1 2009, 9:17 pm
From: Germán Schuager <gschua...@gmail.com>
Date: Sun, 1 Feb 2009 23:17:25 -0300
Local: Sun, Feb 1 2009 9:17 pm
Subject: Re: NH facility: lazy session factory construction

I like your solution. It is cleaner and it doesn't need a proxy.
I'm already using this, it works ok.
Thank you.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tuna Toksoz  
View profile  
 More options Feb 2 2009, 9:48 am
From: Tuna Toksoz <tehl...@gmail.com>
Date: Mon, 2 Feb 2009 16:48:03 +0200
Local: Mon, Feb 2 2009 9:48 am
Subject: Re: NH facility: lazy session factory construction

I have written a blogpost about ComponentActivator's here for future
reference. I hope you don't get this as an advertisement.

http://www.tunatoksoz.com/post/Castle-Custom-Component-Activators.aspx

Tuna Toksöz
http://tunatoksoz.com
http://twitter.com/tehlike

Typos included to enhance the readers attention!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »