Loading ...

How To Use Autofac In Acumatica With Global Graph And Single Registration

Hello everybody,

today I want to leave a short notice on how to use Autofac in Acumatica, but with single registration. In another article I've descirbed how to use Autofac for resolving interface < -- > class implementation. 

But one of my collegues Deebhan Hari pointed that with my usage registration of classes will happen on each roundtrip and for each graph leading to potential memory leack.

Definetely not something, we would like to have. After small conversation, we managed to add to Autofac singleton, which allowed us to have situation when only once per lifetime of the process Autofac 

registers class only once.

 

 

using System;

using PX.Data;

using Autofac;

 

namespace SingleRegistrationDemo

{

       public class AllGraphsExtension : PXGraphExtension<PXGraph>

       {

         public override void Initialize()

         {

             // Implemented Singleton, so that our KNCustomCaseCommonEmailProcessor is registered only once when needed.

             var single = SingletonCustomCaseCommon.Instance;

         }

       }

 

    public sealed class SingletonCustomCaseCommon

    {

        private static readonly Lazy<SingletonCustomCaseCommon>

            lazy =

            new Lazy<SingletonCustomCaseCommon>

                (() => new SingletonCustomCaseCommon());

 

        public static SingletonCustomCaseCommon Instance { get { return lazy.Value; } }

 

        private SingletonKNCustomCaseCommon()

        {

            PX.Objects.EP.EmailProcessorManager.Register(new ClosedCasesReOpenV2.CustomCaseCommonEmailProcessor());

        }

    }

}

Ready to optimize your Acumatica solutions?

If you’re looking to implement advanced customizations like the Autofac singleton registration, but need expert guidance tailored to your specific business needs, we can help! Don’t hesitate to leave a request for your own customization needs. Our team of experienced developers is ready to craft the perfect solution for your project, ensuring optimal performance and scalability.

Contact us today to discuss how we can enhance your Acumatica implementation!