using Funq; using System; class ExampleClass { static void Main() { var container = new Container(); // Register a singelton instance of a service container.Register(() => new Service(), ReuseScope.Singleton); // Resolve the instance from the container var service = container.Resolve (); // Use the service service.DoWork(); } } class Service { public void DoWork() { Console.WriteLine("Service is doing some work"); } }
using Funq; using System; class ExampleClass { static void Main() { var container = new Container(); // Register a transient instance of a service container.RegisterThis example shows how to register and use multiple transient instances of a service. The ReuseScope.Transient parameter ensures that a new instance of the service is created every time it is resolved from the container. This allows for multiple instances of the same service with different states to be used in the application. Package library: Funq is a standalone package library for .NET, meaning it does not come packaged with another library or framework. It can be installed through NuGet.(() => new Service(), ReuseScope.Transient); // Resolve multiple instances from the container var service1 = container.Resolve (); var service2 = container.Resolve (); // Use the services service1.DoWork(); service2.DoWork(); } } class Service { public static int counter = 0; public Service() { counter++; } public void DoWork() { Console.WriteLine("Service is doing some work: " + counter); } }