Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var factory = new Factory("MyApp", new MyLogger());

            // Register the type.
            factory.Type<IMyType>(typeof(MyType));

            // Create an instance and pass in constructor arguments.
            var myFactoryCreatedObject = factory.CreateInterface<IMyType>("Hello", "Factory");

            Console.WriteLine(myFactoryCreatedObject.Message);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var factory = new Factory("MyApp", new MyLogger());

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

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

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

            // Register a dependency.
            factory.Dep<IMyDependency>(new MyDependency());

            // Register the type.
            factory.Type<IMyType>(typeof(MyType));

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

            Console.WriteLine(myFactoryCreatedObject.Message);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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();
        }