Exemple #1
0
        static void Main(string[] args)
        {
            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <IApplication>();
                app.Run();
            }
        }
        static void Main(string[] args)
        {
            var container = ContainerConfig.Configure(); //Instantiate DI container.

            using var scope = container.BeginLifetimeScope();
            var app = scope.Resolve <IApplication>();

            app.Run();

            Console.ReadLine();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var container = ContainerConfig.Configure(); //configure the container, and the container is what holds all of our instantiation set up for how to instantiate something

            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <IApplication>(); // i need an IApplication object,   check the url 27:00
                app.Run();
            }

            Console.ReadLine();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            IContainer container = ContainerConfig.Configure();

            using (ILifetimeScope scope = container.BeginLifetimeScope())
            {
                IBusinessLogic businessLogic = scope.Resolve <IBusinessLogic>();
                businessLogic.ProcessData();
            }

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <IApplication>();//this line means - need an object of the IApplication/Application
                app.Run();
            }

            Console.ReadLine();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            // https://autofac.org/

            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <IApplication>();
                app.Run();
            }

            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            //Create the IoC container
            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                //Create a new instance of Application and run it
                var app = scope.Resolve <IApplication>();;
                app.Run();
            }

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //BusinessLogic businessLogic = new BusinessLogic();
            //businessLogic.ProcessData();

            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <IApplication>();
                app.Run();
            }

            Console.ReadLine();
        }
Exemple #9
0
        static void Main(string[] args)
        {
            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                //var app = scope.Resolve<IApplication>();
                //app.Run();

                //===Same thing as :
                var app = scope.Resolve <IBusinessLogic>();
                app.ProcessData();
            }

            Console.ReadLine();
        }
Exemple #10
0
        /// <summary>
        /// Getting instances from container config. BUT Main is a static class -> cannot be instanciated and it is required coze passed via constructor
        /// BUT main-entrypoint of program shall be within autofac as well. Deshalb: create a new Class/Interface called Application
        /// BIG Advantage: TESTING the application decoupled! -> MOCKING is possible for each sub-dependency
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Create Factory or primary Autofac to create instances and wire it up using the ContainerConfig
            // This configures the container that is holding all our design for instanciating data and classes
            var container = ContainerConfig.Configure();

            // setting a new scope for instances that are passed out / created. //(typically)
            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <IApplication>();
                app.Run();
            }


            Console.ReadLine();
        }
        //TO TEST DEPENDENCY INJECTION TRY ADDING A CLASS THEN Have it Implement an Interface, then change its constructer(interface Createdobject, Interface CreatedData)
        //Loosy Coupled
        //Only things that change is Contructor() and Old Class that WAS implemented by that Interface HAHAH! YES!!!

        static void Main(string[] args)
        {
            //Wire up your container Creates instances or Factory Check Container Class
            // newing up instances in Container, Don't Put them in static classes!

            var container = ContainerConfig.Configure();

            //Standard uses for Dependency injection got BeginLifetimeScope
            using (var scope = container.BeginLifetimeScope())
            {
                //using scope object to Give IAPPLICATION Manually
                var app = scope.Resolve <IApplication>();
                app.Run();
            }

            Console.ReadLine();
        }
Exemple #12
0
        static void Main(string[] args)
        {
            var container = ContainerConfig.Configure();


            // now this is interesting, we had businessLogic created by new() here and we didnt want that
            // set up a new scope for container
            using (var scope = container.BeginLifetimeScope())
            {
                // ?I need an IApplication object, this goes to container, uses that to get IApplication manually
                // if this methd was used extensively then somethign is wrong in way your app is designed,
                // should onlybe used once for initial hook
                var app = scope.Resolve <IApplication>();
                app.Run();
            }

            Console.ReadLine();
        }
Exemple #13
0
        /* Make sure these are running. Should have been automatically executed by docker-compose
         * Note that this is for PowerShell and not cmd. Should be posssible to rewrite for cmd
         *
         * docker run -p 5432:5432 --rm -e POSTGRES_PASSWORD=password -d postgres
         * docker run -ti --rm -v $ENV:UserProfile/source/repos/container-knowledge-sharing/HelloCompose/DemoLibrary/db_scripts:/flyway/sql flyway/flyway -url=jdbc:postgresql://host.docker.internal/ -schemas=postgres -user=postgres -password=password migrate
         */
        static void Main(string[] args)
        {
            /* Docker-compose is not too intelligent when it comes to knowing if
             * it is safe to proceed with the launching of containers. This means
             * you risk your application connecting to a DB before the migration
             * is completed!
             */
            System.Threading.Thread.Sleep(5000);
            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <IApplication>();
                app.Run();
            }

            Console.ReadLine();
        }