예제 #1
0
        static void Main(string[] args)
        {
            var logger = new MyLogger();
            var factory = new Factory("MyApp", logger);

            // Auto register types.
            factory.AutoRegisterTypes();

            // Normal singleton bootstrapping... although the lazy singleton isn't instantiated yet.
            factory.AutoInstantiateSingletons();

            // Create an instance.
            // This will instantiate the lazy singleton at the point when it is requested by the dependency injection system.
            var myFactoryCreatedObject = factory.CreateInterface<IMyType>();

            Console.WriteLine(myFactoryCreatedObject.Message);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var logger = new MyLogger();
            var factory = new Factory("MyApp", logger, new Reflection());

            // Auto register types.
            factory.AutoRegisterTypes();

            // Auto bootstrap singletons for classes marked as [Singleton].
            factory.AutoInstantiateSingletons();

            // Create an instance.
            var myFactoryCreatedObject = factory.CreateInterface<IMyType>();

            Console.WriteLine(myFactoryCreatedObject.Message);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var logger = new MyLogger();
            var factory = new Factory("MyApp", logger);

            // Auto register types.
            factory.AutoRegisterTypes();

            // Auto bootstrap singletons for classes marked as [Singleton].
            var singletonManager = factory.AutoInstantiateSingletons();

            // Start-up startable singletons.
            singletonManager.Startup();

            // Create an instance.
            var myFactoryCreatedObject = factory.CreateInterface<IMyType>();

            Console.WriteLine(myFactoryCreatedObject.Message);

            // Shutdown startable singletons.
            singletonManager.Shutdown();
        }