skip to Main Content

I have an .NET 7 REST API which has singleton class initialization.

It is working fine with single instance, and it fails with multiple instances.

Below is my singleton initialization.

Engine _engine = new Engine(loggerFactory);
builder.Services.AddSingleton<Engine>(_engine); 

This functionality mainly deletes/load folder to the wwwroot directory.

Could someone give me a solution on making use of multiple instances with singleton class.

2

Answers


  1. Chosen as BEST ANSWER

    Issue is fixed by dropping the files under the machine name


  2. could someone give me a solution on making use of multiple instances with singleton class.

    Ensuring to run only single instance of the Azure Function App runs at a time is the responsibility of SingletonAttribute class.

    This class also other feature in limiting the instances count that runs at that time and that impacts the scalability and performance.

    That feature is the Mode property of the FunctionInvocation attribute and the syntax is:

    Mode = Function / Listener

    [Singleton(Mode = SingletonMode.Listener)]
    [FunctionName("ListenerTest")]
    

    If the mode property is Listener, then it does the single instance execution and Function mode can give you run multiple instances and simultaneous executions but ensures that only one instance processes a given function invocation at a time.

    Refer to this MS Doc and medium article by the author @yu_ka1984 for more information on using the SingletonAttributeFunctionInvocationMode for running the multiple instances.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search