Пример #1
0
        static void Main(string[] args)
        {
            var container = IoCBuilder.Build();

            using (var scope = container.BeginLifetimeScope())
            {
                var _personService = scope.Resolve <IPersonService>();

                // Demo Cases:

                // _personService.PrintPersonIds();
                // _personService.PrintAllPeople();
                // _personService.PrintAllCities();
                // _personService.PrintPersonById(5);
                // _personService.SavePerson(PersonUtils.CreateValidPerson());
                // _personService.SavePerson(PersonUtils.CreateInvalidPerson());
                // _personService.EditPerson(PersonUtils.CreatePersonForEdit());
                // _personService.EditPerson(PersonUtils.CreatePersonForEdit(3));
                // _personService.DeletePerson(4);

                // Note: You can call any of the first 4 Methods
                // multiple times consecutively, to test if the
                // caching works properly (only 1 of the same query
                // will be fired)
            }
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "UserAPI", Version = "v1"
                });
            });
            services.AddControllers().AddControllersAsServices();
            services.AddMemoryCache();


            services.AddCors(o => o.AddPolicy("AllowAll", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));

            //services.AddCors(o => o.AddPolicy("AllowAll",
            // builder =>
            // {
            //     builder
            //         .AllowAnyOrigin()
            //         //.AllowAnyMethod()
            //         //.AllowAnyHeader()
            //         //.AllowCredentials();
            // }));
            IoCBuilder.Build(services, this.Configuration);
        }
Пример #3
0
        static void Main(string[] args)
        {
            // -------------- Default --------------
            var builder1 = new IoCBuilder();

            builder1.RegisterType <IService, Service>(LifeTime.Default);

            var container1 = builder1.Build();

            var obj1 = container1.Resolve <IService>();
            var obj2 = container1.Resolve <IService>();

            Console.WriteLine($"{nameof(obj1)} = {nameof(obj2)} : {obj1 == obj2}");

            // -------------- Singleton --------------

            var builder2 = new IoCBuilder();

            builder2.RegisterType <IService, Service>(LifeTime.Singleton);

            var container2 = builder2.Build();

            var obj3 = container2.Resolve <IService>();
            var obj4 = container2.Resolve <IService>();

            Console.WriteLine($"{nameof(obj3)} = {nameof(obj4)} : {obj3 == obj4}");

            Console.WriteLine($"{nameof(obj1)} = {nameof(obj3)} : {obj1 == obj3}");

            // -------------- Loaded by path --------------

            var builder3 = new IoCBuilder();

            builder3.RegisterByPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\Models\\bin\\Debug"), typeof(object));
            var container3 = builder3.Build();

            var obj5 = container3.Resolve <object[]>();

            Console.WriteLine($"Loaded by path {(obj5 != null ? "succeeded" : "failed")}, number of instances {obj5?.Length}");

            // -------------- Plugin --------------

            try
            {
                var plugins = container3.LoadPlugins(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\Plugins\\bin\\Debug"));
                Console.WriteLine($"{plugins.Length} plugins loaded");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to load plugins - {ex.Message}");
                throw;
            }


            Console.ReadLine();
        }
Пример #4
0
        static void Main(string[] args)
        {
            Container = IoCBuilder.Build();

            //var view = new MainView(new ViewModel.MainViewModel());

            var view = Container.Resolve <MainView>();

            view.Run();
        }
Пример #5
0
 static void Main(string[] args)
 {
     IoCBuilder.Build();
     var allProducts = new List<ProductVM>();
     var percentagePrices = new List<double>() { PercentageMoneyConstant.USDollar, PercentageMoneyConstant.Euro };
     allProducts.AddRange(productService.GetWithoutPercentage(myDinamycList, MethodConstant.GetAll));
     allProducts.AddRange(productService.GetWithPercentage(myDinamycList, MethodConstant.GetAll, percentagePrices));
     printService.PrintDetailsProducts(allProducts);
     Console.ReadLine();
 }
Пример #6
0
        public void SingletonInstance()
        {
            var builder = new IoCBuilder();

            builder.RegisterType <IService, Service>(LifeTime.Singleton);

            var container = builder.Build();

            var obj1 = container.Resolve <IService>();
            var obj2 = container.Resolve <IService>();

            Assert.AreEqual(obj1, obj2);
        }
Пример #7
0
        public void DefaultInstances()
        {
            var builder = new IoCBuilder();

            builder.RegisterType <IService, Service>(LifeTime.Default);

            var container = builder.Build();

            var obj1 = container.Resolve <IService>();
            var obj2 = container.Resolve <IService>();

            Assert.AreNotEqual(obj1, obj2);
        }
Пример #8
0
        public void LoadedByPath()
        {
            var builder = new IoCBuilder();

            builder.RegisterByPath("..\\..\\..\\Models\\bin\\Debug", typeof(object));

            var container = builder.Build();

            var instances = container.Resolve <object[]>();

            Assert.IsNotNull(instances);
            Assert.AreEqual(instances.Length, 1);
        }
Пример #9
0
        static void Main(string[] args)
        {
            // Adding logger
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .WriteTo.Console()
                         .WriteTo.File("logs.log")
                         .CreateLogger();

            // Resolving dependencies and initilize application loop.
            var appContainer = IoCBuilder.Build();

            using (var application = appContainer.BeginLifetimeScope())
            {
                application.Resolve <GameUI>();
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            var builder1 = new IoCBuilder();

            builder1.RegisterType <IService, Service>(LifeTime.Default);

            var container1 = builder1.Build();

            var obj1 = container1.Resolve <IService>();
            var obj2 = container1.Resolve <IService>();

            Console.WriteLine($"{nameof(obj1)} = {nameof(obj2)} : {obj1 == obj2}");

            var builder2 = new IoCBuilder();

            builder2.RegisterType <IService, Service>(LifeTime.Singleton);

            var container2 = builder2.Build();

            var obj3 = container2.Resolve <IService>();
            var obj4 = container2.Resolve <IService>();

            Console.WriteLine($"{nameof(obj3)} = {nameof(obj4)} : {obj3 == obj4}");

            Console.WriteLine($"{nameof(obj1)} = {nameof(obj3)} : {obj1 == obj3}");


            var builder3 = new IoCBuilder();

            builder3.RegisterByPath($"{AppDomain.CurrentDomain.BaseDirectory}..\\..\\..\\..\\Models\\bin\\Debug\\netcoreapp2.0", typeof(object));
            var container3 = builder3.Build();

            var obj5 = container3.Resolve <object[]>();

            Console.ReadLine();
        }
Пример #11
0
 public void InitializeTest()
 {
     IoCBuilder.Build();
 }