I'm calling it only once using Autofac

public class AutofacConfig {

    public static void RegisterContainer( HttpConfiguration config ) {
      var builder = new ContainerBuilder();
 builder.Register(x => 
NHibernateHelper.GetSessionFactory()).SingleInstance();
}


On Friday, January 16, 2015 at 12:56:38 PM UTC-8, fba wrote:
>
> Why rebuilding the factory each Time ?
>
> Envoyé de mon iPhone
>
> Le 16 janv. 2015 à 20:11, Rip MJ <[email protected] <javascript:>> a 
> écrit :
>
> Here is my code .It's a static method and a singleton pattern.
>
> public static ISessionFactory GetSessionFactory()
>
> {
>     lock (factorylock)
>     {
>         if (_sessionFactory == null)
>         {
>
>   string scriptLocation = HttpContext.Current.IsDebuggingEnabled
>     ? HostingEnvironment.MapPath( 
> ConfigurationManager.AppSettings["GetDataBaseScript"] )
>     : null;
>
>   FluentConfiguration config = Fluently
>       //// Start the configuration
>     .Configure() **--- This is the place where 5% of memory is being used**
>       // Setup the database configuration
>     .Database(
>       // Configure for MS SQL Server connection
>       MsSqlConfiguration
>       // use MS SQL Server 2010
>         .MsSql2008
>       // Specify the connection string
>         .ConnectionString(c => 
> c.FromConnectionStringWithKey("DatabaseConnection"))
>     )
>
>
>
>     // Set up the mappings
>     .Mappings( maps =>
>       maps
>         Setup mappings
>         .AutoMappings
>         // Load mappings from assembly
>         .Add( AutoMap
>           // Load auto maps configuration from assembly
>           .AssemblyOf<AutoMapConfiguration>(new AutoMapConfiguration() )
>           // Specify some custom conventions for Auto Map
>           .Conventions.AddFromAssemblyOf<AutoMapConfiguration>()
>
>           // Override some automapping configuration
>           .UseOverridesFromAssemblyOf<AutoMapConfiguration>()
>         )
>
>     );
>
>
>   // determine if we need to generate the DB or just build the configuration
>   if( !String.IsNullOrEmpty( scriptLocation ) ) {
>     // Where to generate the script file
>     // Expose the configuration
>     config.ExposeConfiguration( c => {
>       // Export the schema
>       new SchemaExport( c )
>         // Specify where the script is to be exported
>         .SetOutputFile( scriptLocation )
>         .Create( true, false );
>     } );
>   } else {
>     // Build the configuration
>     config.BuildConfiguration();
>   }
>
>   // Return the NHibernate Session Factory
>    _sessionFactory = config.BuildSessionFactory(); **--- This is the place 
> where 20% is being used**
>         }
>         return _sessionFactory;
>     }
>
> }
>
>
> On Thursday, January 15, 2015 at 11:36:52 AM UTC-8, fba wrote:
>>
>> Without the code hard to say... I would think that you Forget to make you 
>> factory static...
>>
>> Envoyé de mon iPhone
>>
>> Le 15 janv. 2015 à 18:43, Rip MJ <[email protected]> a écrit :
>>
>> I'm using fluent nhibernate in my application and it's functioning very 
>> well except it has high memory consumptions.The CPU utilization spikes up 
>> very  frequently and the website crashes.What would be the problem ? I 
>> checked the data calls and they don't seem to take much time.I profiled the 
>> application using ANTS performance profiler and found that Getsession 
>> factory is consuming 20% of the CPU.Can anyone help me figuring out where i 
>> am going wrong.I am attaching the PDF from the profiled application
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "nhusers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/nhusers.
>> For more options, visit https://groups.google.com/d/optout.
>>
>> <Fluent Nhibernate.pdf>
>>
>>  -- 
> You received this message because you are subscribed to the Google Groups 
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>
> .
> Visit this group at http://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to