Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var container = new LightInject.ServiceContainer();

            container.Register <IFoo, Foo>();
            var instance = container.GetInstance <IFoo>();

            //Assert.IsInstanceOfType(instance, typeof(Foo));
            container.Register <IBar, Bar>();
            var foo = container.GetInstance <IFoo>();

            foo.DoFooStuff();

            Console.WriteLine("Hello World!");
            //IPersistencia persistencia = new Persistencia();
            //IPersistencia persistencia = null; //deberia instanciarse
            Secretaria secretaria = new Secretaria(foo);
            Estudiante estudiante = new Estudiante("Edison", "Molina");
            // crear los movimientos en el avatar
            Curso curso = new Curso("Programacion");

            //se  graba donde se indique el objeto persistencia

            secretaria.Matricular(estudiante, curso);
        }
Exemplo n.º 2
0
 private static void SetLightInjectContainer()
 {
     var container = new LightInject.ServiceContainer();
     container.RegisterApiControllers(Assembly.GetExecutingAssembly());
     container.Register<IUnitOfWork, UnitOfWork>(new PerScopeLifetime());
     container.Register(typeof(RepositoryBase<>), typeof(IRepository<>));
     container.EnableWebApi(new HttpConfiguration());
 }
Exemplo n.º 3
0
 public IoCContainer()
 {
     _container.SetDefaultLifetime <PerContainerLifetime>();
     _container.Register <IFieldWorker, FieldWorker>();
     _container.Register <IMapWorker, MapCreator> ();
     _container.Register <ILocationManager, LocationManager>();
     _container.Register <IPlayerCreator, PlayerCreator>();
 }
Exemplo n.º 4
0
        private static void SetLightInjectContainer()
        {
            var container = new LightInject.ServiceContainer();

            container.RegisterApiControllers(Assembly.GetExecutingAssembly());
            container.Register <IUnitOfWork, UnitOfWork>(new PerScopeLifetime());
            container.Register(typeof(RepositoryBase <>), typeof(IRepository <>));
            container.EnableWebApi(new HttpConfiguration());
        }
        public static LightInject.ServiceContainer PrepareLightInject()
        {
            var c = new LightInject.ServiceContainer();

            c.Register <Parameter1>();
            c.Register <Parameter2>(new PerContainerLifetime());
            c.Register <Parameter3>(new PerScopeLifetime());

            c.Register <ScopedBlah>(new PerScopeLifetime());

            return(c);
        }
Exemplo n.º 6
0
 private static void RegisterRepositories(ServiceContainer serviceContainer)
 {
     serviceContainer.Register <ICustomerRepository, CustomerRepository>(Lifetime);
     serviceContainer.Register <ICustomerPhoneNumberRepository, CustomerPhoneNumberRepository>(Lifetime);
     serviceContainer.Register <ICityRepository, CityRepository>(Lifetime);
     serviceContainer.Register <IAnnouncementRepository, AnnouncementRepository>(Lifetime);
     serviceContainer.Register <IAnnouncementImageRepository, AnnouncementImageRepository>(Lifetime);
     serviceContainer.Register <IAnnouncementTypeRepository, AnnouncementTypeRepository>(Lifetime);
     serviceContainer.Register <IDocumentTypeRepository, DocumentTypeRepository>(Lifetime);
     serviceContainer.Register <IRepairRepository, RepairRepository>(Lifetime);
     serviceContainer.Register <IPropertyTypeRepository, PropertyTypeRepository>(Lifetime);
     serviceContainer.Register <IPhoneNumberRepository, PhoneNumberRepository>(Lifetime);
 }
Exemplo n.º 7
0
 private static void RegisterServices(ServiceContainer serviceContainer)
 {
     serviceContainer.Register <CustomerService>(Lifetime);
     serviceContainer.Register <CustomerPhoneNumberService>(Lifetime);
     serviceContainer.Register <CityService>(Lifetime);
     serviceContainer.Register <AnnouncementService>(Lifetime);
     serviceContainer.Register <AnnouncementImageService>(Lifetime);
     serviceContainer.Register <AnnouncementTypeService>(Lifetime);
     serviceContainer.Register <DocumentTypeService>(Lifetime);
     serviceContainer.Register <RepairService>(Lifetime);
     serviceContainer.Register <PropertyTypeService>(Lifetime);
     serviceContainer.Register <PhoneNumberService>(Lifetime);
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            var container = new LightInject.ServiceContainer();

            container.Register <IFoo, Foo>(new PerContainerLifetime());
            container.Register <IFoo, Foo2>(new PerContainerLifetime());
            //container.Register(typeof(IFoo<>), typeof(Foo<>));
            var a = container.GetInstance <IFoo>();

            Console.WriteLine(a.GetHashCode());
            var b = container.GetInstance <IFoo>();

            Console.WriteLine(b.GetHashCode());
            Console.WriteLine("done");
            Console.Read();
        }
Exemplo n.º 9
0
        static IOCTest()
        {
            var containerIoc = new LightInject.ServiceContainer();

            IOCTest.Container = containerIoc;
            var item = new IOCTestItem();

            containerIoc.Register <IIOCTestItem>(x => item);
        }
Exemplo n.º 10
0
        static void Main1(string[] args)
        {
            var container = new LightInject.ServiceContainer();

            container.RegisterRouter(new IRouterConfigurationSource[] { new RouterConfigurationSourceSample() });
            container.RegisterFrom <ServiceLocatorCompositionRoot>();
            container.RegisterAzureServiceBusRouter();

            container.Register <IMessageHandler, MessageHandler>(typeof(MessageHandler).FullName, new PerContainerLifetime());

            var host = container.GetInstance <IHost>();

            host.Configuration.UsingAzureServiceBus();
            host.Run();
            Console.ReadLine();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            //Retrieve url path of HelloWorldAPI
            string urlPath = ConfigurationManager.AppSettings["HelloWorldAPIURL"];

            //Resolve instance of Interface
            var container = new LightInject.ServiceContainer();

            container.Register <IErrorLogger, ErrorLogger>();
            var logger = container.GetInstance <IErrorLogger>();

            IFileLog fileLog = new FileLogger();

            var client = new RestClient(urlPath);

            try
            {
                //Execute the API Call
                IRestResponse response = client.Execute <List <HelloWorldController.Models.GreetingModel> >(new RestRequest());

                if (response != null)
                {
                    if (response.Content != null)
                    {
                        GreetingModel dataReceived = new GreetingModel();
                        dataReceived = JsonConvert.DeserializeObject <GreetingModel>(response.Content);
                        Console.WriteLine(dataReceived.greetingMessage);
                        Console.Read();
                    }
                    else
                    {
                        var errorMsg = "Error occured in restSharp. Error Message: " + response.ErrorMessage +
                                       "Error Status Description: " + response.StatusDescription;

                        //Log the error.
                        fileLog.WriteToFile(errorMsg);
                    }
                }
            }
            catch (Exception ex)
            {
                // Log the exception
                logger.DisplayErrorMessage(ex.InnerException.ToString());
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            //*** ioc test ****/
            //var identity = new DummExtensions() ;
            ClaimsIdentity i;
            ClaimTypes

            /*** redis test *///
            var container = new LightInject.ServiceContainer();
            var pool      = new BasicRedisClientManager(0, "localhost:6380");

            container.Register <IRedisClientsManager>(x => pool,
                                                      new PerContainerLifetime());
            using (var client = container.GetInstance <IRedisClientsManager>().GetClient())
            {
                //client.set
                var dummyClient = client.As <DummyClass>();

                var dummyObject = new DummyClass()
                {
                    Id = dummyClient.GetNextSequence(), Value = "ggwp"
                };
                long id = dummyObject.Id;

                dummyObject.Items.Add(new DummyItem()
                {
                    Name = "i1"
                });
                dummyObject.Items.Add(new DummyItem()
                {
                    Name = "i2"
                });
                dummyClient.Store(dummyObject);
                dummyClient.ExpireIn(id, TimeSpan.FromMinutes(30));
                dummyClient.Delete(dummyObject);
                var obj = dummyClient.GetById(id);
                id = 1;
                var obj2 = dummyClient.GetById(10);
                dummyClient.ExpireIn(11, TimeSpan.FromMinutes(20));
                var contextClient = client.As <DummyContext>();
                var context1      = new DummyContext()
                {
                    Id = 1
                };
                contextClient.Store(context1);
                var context2 = new DummyExtendedContext()
                {
                    Id = 2, ItWorks = "true"
                };
                //contextClient.Store(context2);
                obj.storeContext(client, context2);

                var sessionClient = client.As <HttpSession>();
                var session       = new HttpSession()
                {
                    Name = "hehehey"
                };
                sessionClient.Store(session);
                Console.WriteLine(obj.Id);
                Console.ReadLine();
            }

            //using (var cache = pool.GetCacheClient())
            //{
            //    var dc = cache.Add<DummyClass>()
            //}
        }
Exemplo n.º 13
0
 public void Register <TService, TImplementation>() where TImplementation : TService
 {
     _container.Register <TService, TImplementation>();
 }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            var container = new LightInject.ServiceContainer();

            container.Register <ApplicationInformation>(c => new ApplicationInformation("ShinyMusicSynchronizer", 1, 0), new PerContainerLifetime());
            container.Register <PortableDeviceCollection>(c => CreatePortableDeviceCollectionFromApplicationInformation(c.GetInstance <ApplicationInformation>()));

            container.Register <IUserInterface, ConsoleUserInterface>(new PerContainerLifetime());
            container.Register <Action <ICommandMessage> >(c => new Action <ICommandMessage>(c.GetInstance <IUserInterface>().ReportMessage));

            container.Register <Options>(c => CliParser.StrictParse <Options>(args), new PerContainerLifetime());
            container.Register <OptionsToCommandParser, OptionsToCommandParser>();
            container.Register <ListDevicesCommand.Options>(c => c.GetInstance <Options>().ListDevices);
            container.Register <ListDevicesCommand, ListDevicesCommand>();
            container.Register <SynchronizeCommand.Options>(c => c.GetInstance <Options>().Synchronize);
            container.Register <SynchronizeCommand, SynchronizeCommand>();
            container.Register <ICommand>(c => c.GetInstance <OptionsToCommandParser>().CreateCommandFromOptions());

            var command = container.GetInstance <ICommand>();

            command.Execute();
        }