Exemplo n.º 1
0
        static void Main(string[] args)
        {
            _container = new Container();
            _container.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle();
            _container.Register <IHelloWorldService, HelloWorldService>(Lifestyle.Scoped);
            SimpleInjectorAccessor.RegisterContainer(_container);

            SimpleInjectorAccessor.Load(HelloWorldServiceInjector.LoadTypes);

            _container.Verify();

            using (_container.BeginLifetimeScope())
            {
                try
                {
                    var isCodingExercise = Convert.ToBoolean(ConfigurationSettings.AppSettings["isCodingExercise"]);
                    _helloWorldService = _container.GetInstance <IHelloWorldService>();

                    var result = _helloWorldService.GetStartMessage(isCodingExercise);

                    Console.WriteLine(result);
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.WriteLine("An error occurred.");
                    Console.ReadLine();
                }
            }
        }
Exemplo n.º 2
0
        static Program()
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            SimpleInjectorAccessor.RegisterContainer(container);
            SimpleInjectorAccessor.Load(CoreSampleAppInjectorModule.LoadTypes);
        }
Exemplo n.º 3
0
        private void InitializeContainer(IApplicationBuilder app)
        {
            SimpleInjectorAccessor.RegisterContainer(container);
            // Add application presentation components:
            container.RegisterMvcControllers(app);
            container.RegisterMvcViewComponents(app);

            container.Register <IConfiguration>(() => Configuration);

            // Add application services.
            CoreSampleAppIntranetWebInjectorModule.LoadTypes(container);

            // Allow Simple Injector to resolve services from ASP.NET Core.
            container.AutoCrossWireAspNetComponents(app);
        }
        public static void LoadTypes(Container container)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
#if DEBUG
                                .AddJsonFile("appsettings.Development.json")
#endif
                                .Build();

            container.Register <IConfiguration>(() => configuration);

            var identity = new GenericIdentity("Processor");

            container.Register <IIdentity>(() => identity);

            SimpleInjectorAccessor.Load(CoreSampleAppBusinessInjectorModule.LoadTypes);
        }
        public AdventureWorks2017Context CreateDbContext(string[] args)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            SimpleInjectorAccessor.RegisterContainer(container);

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();


            container.Register <IConfiguration>(() => configuration);

            var identity = new GenericIdentity("Migration");

            container.Register <IIdentity>(() => identity);

            return(new AdventureWorks2017Context());
        }
Exemplo n.º 6
0
 public static void LoadTypes(Container container)
 {
     container.Register <IIdentity>(() => SimpleInjectorAccessor.Container.GetInstance <IHttpContextAccessor>().HttpContext.User.Identity, Lifestyle.Transient);
     SimpleInjectorAccessor.Load(CoreSampleAppBusinessInjectorModule.LoadTypes);
 }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            SimpleInjectorAccessor.RegisterContainer(container);
            SimpleInjectorAccessor.Load(SampleAppInjectorModule.LoadTypes);

            //List<FileData> fileDatas = new List<FileData>();
            //using (TextFieldParser csvReader = new TextFieldParser("path"))
            //{
            //    csvReader.SetDelimiters(new string[] { "," });
            //    csvReader.HasFieldsEnclosedInQuotes = true;
            //    int row = 1;
            //    while (!csvReader.EndOfData)
            //    {
            //        string[] fieldData = csvReader.ReadFields();
            //        // Code to build an entry or perform other actions goes here
            //        for(int col = 0; col < fieldData.Length; col++)
            //        {
            //            fileDatas.Add(new FileData()
            //            {
            //                FileId = 0,
            //                RowNum = row,
            //                ColNum = col,
            //                Value = fieldData[col]
            //            });
            //        }
            //        row++;
            //    }
            //}
            ////Bulk insert data from the list

            var    productService = SimpleInjectorAccessor.Container.GetInstance <IProductService>();
            int    id;
            string entry;

            do
            {
                Console.Write("Enter Product Id:  ");
                entry = Console.ReadLine();
                if (int.TryParse(entry, out id))
                {
                    var product = productService.GetProductById(id);

                    if (product != null)
                    {
                        Console.WriteLine($"Name: {product.Name}\nPrice: {product.ListPrice}");
                    }
                    else
                    {
                        Console.WriteLine("Product Not Found");
                    }
                }
                else
                {
                    Console.WriteLine("Failed");
                }
            } while (entry != "quit");
        }
 public static void LoadTypes(Container container)
 {
     SimpleInjectorAccessor.Load(SampleAppServicesInjectorModule.LoadTypes);
 }