public async void Run(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                Deferral = taskInstance.GetDeferral();
                var containerFactory = new ContainerFactory();
                containerFactory.AddRegistrations(builder =>
                {
                    var uwpRegistrations = new UWPPlatformServicesRegistrator();
                    uwpRegistrations.RegisterPlatformSpecificServices(builder);
                });

                var container    = containerFactory.Build();
                var synchronizer = container.Resolve <ISynchronizer>();

                var serverOnline = await synchronizer.Synchronize();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.ToString());
            }
            finally
            {
                Deferral.Complete();
            }
        }
            public void Test()
            {
                var primaryAssembly = AssemblyCompiler.Compile(primaryAssemblyCode);
                var assemblyName    = primaryAssembly.GetName().Name;

                CopyAssemblyToTestDirectory(primaryAssembly);
                CopyAssemblyToTestDirectory(typeof(IContainer).Assembly);
                CopyAssemblyToTestDirectory(Assembly.GetExecutingAssembly());
                CopyAssemblyToTestDirectory(typeof(Assert).Assembly);

                GetInvoker().DoCallBack(assemblyName, delegate(string s)
                {
                    var f = new ContainerFactory()
                            .WithAssembliesFilter(x => x.Name.StartsWith("tmp_"))
                            .WithTypesFromDefaultBinDirectory(false);
                    var type = Type.GetType("A1.ISomeInterface, " + s);
                    Assert.That(type, Is.Not.Null);
                    using (var c = f.Build())
                    {
                        var exception  = Assert.Throws <SimpleContainerException>(() => c.Get(type));
                        var assemblies = new[] { "SimpleContainer", s }.OrderBy(x => x).Select(x => "\t" + x).JoinStrings("\r\n");
                        const string expectedMessage = "no instances for [ISomeInterface]\r\n\r\n!" +
                                                       "ISomeInterface - has no implementations\r\n" +
                                                       "scanned assemblies\r\n";
                        Assert.That(exception.Message, Is.EqualTo(expectedMessage + assemblies));
                    }
                });
            }
Ejemplo n.º 3
0
        public AutofacSlimCreateOperator()
        {
            var cfg = UploaderConfigFile.Parse(UploaderCfg.Localhost);

            Certificator.AllowFrom(cfg.CertificateThumb);

            _container = ContainerFactory.Build(cfg);
        }
Ejemplo n.º 4
0
            public void Test()
            {
                var referencedAssembly = AssemblyCompiler.Compile(referencedCode);
                var assembly           = AssemblyCompiler.Compile(code, referencedAssembly);
                var factory            = new ContainerFactory().WithTypesFromAssemblies(new[] { assembly });

                using (var container = factory.Build())
                {
                    var interfaceType = referencedAssembly.GetType("A1.ISomeInterface");
                    Assert.That(container.Get(interfaceType).GetType().Name, Is.EqualTo("SomeInterfaceImpl"));
                }
            }
        public AndroidApplication()
        {
            var factory = new ContainerFactory();

            //Platform registrations
            factory.AddRegistrations(builder =>
            {
                builder.RegisterType <AndroidNavigationManager>().As <INavigationManager>();
                builder.Register <Context>(container => Application.Context);
            });

            this.Container = factory.Build();
        }
            public void Test()
            {
                var assembly = AssemblyCompiler.Compile(testCode);

                File.WriteAllText(configFileName, "A.parameter->11");
                var factory = new ContainerFactory()
                              .WithAssembliesFilter(x => x.Name.StartsWith("tmp_"))
                              .WithConfigFile(configFileName)
                              .WithTypesFromAssemblies(new[] { assembly });
                var e = Assert.Throws <SimpleContainerException>(() => factory.Build());

                Assert.That(e.Message, Is.EqualTo("for name [A] more than one type found [A1.A], [A2.A]"));
            }
Ejemplo n.º 7
0
            public void Test()
            {
                var referencedAssembly = AssemblyCompiler.Compile(referencedCode);
                var a1      = AssemblyCompiler.Compile(code1, referencedAssembly);
                var a2      = AssemblyCompiler.Compile(code2, referencedAssembly);
                var factory = new ContainerFactory()
                              .WithTypesFromAssemblies(new[] { a1, a2 })
                              .WithAssembliesFilter(x => x.Name == a2.GetName().Name);

                using (var container = factory.Build())
                {
                    var interfaceType = referencedAssembly.GetType("A1.ISomeInterface");
                    Assert.That(container.Get(interfaceType).GetType().Name, Is.EqualTo("TestClass2"));
                }
            }
Ejemplo n.º 8
0
        void IntegrateSimpleInjector(IServiceCollection services)
        {
            Container = ContainerFactory.Build();

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddSingleton <IControllerActivator>(
                new SimpleInjectorControllerActivator(Container));

            services.AddSingleton <IViewComponentActivator>(
                new SimpleInjectorViewComponentActivator(Container));

            services.EnableSimpleInjectorCrossWiring(Container);
            services.UseSimpleInjectorAspNetRequestScoping(Container);
        }
Ejemplo n.º 9
0
        public void Configuration(IAppBuilder appBuilder)
        {
            var config = new HttpConfiguration();

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            ContainerFactory.Build(config);
            appBuilder.UseWebApi(config);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            var count = args.Any() ? Convert.ToInt32(args.First()) : 100;

            var container = ContainerFactory.Build(new NonDisposableTypeAsTransient(), new Interceptors());

            var sw = new Stopwatch();

            sw.Start();
            for (var i = 0; i < count; i++)
            {
                var instance = container.Resolve <IService>();
                instance.Run();
            }
            sw.Stop();

            Console.WriteLine("{0:#,##0} instances, {1:0,000} ms", count, sw.ElapsedMilliseconds);
        }
        public App(ContainerFactory containerFactory)
        {
            //InitializeComponent();
            containerFactory.AddRegistrations(builder =>
            {
                builder.Register <Application>(x => Application.Current);
                builder.Register <IContainer>(x => Container);

                builder.RegisterType <ConfigurationPresenter>().As <IConfigurationPresenter>();
                builder.RegisterType <ConfigurationView>().As <IConfigurationView>();
                builder.RegisterType <LoginPresenter>().As <ILoginPresenter>();
                builder.RegisterType <LoginView>().As <ILoginView>();
                builder.RegisterType <VaultExplorerPresenter>().As <IVaultExplorerPresenter>();
                builder.RegisterType <VaultExplorerView>().As <IVaultExplorerView>();
                builder.RegisterType <EntryDetailsPresenter>().As <IEntryDetailsPresenter>();
                builder.RegisterType <EntryDetailsView>().As <IEntryDetailsView>();

                //=== Platform Specific
                var platformServicesRegistrator = DependencyService.Get <IPlatformServicesRegistrator>();
                platformServicesRegistrator.RegisterPlatformSpecificServices(builder);
            });

            Container = containerFactory.Build();


            var configurationManager          = Container.Resolve <IMobileConfigurationReader>();
            var presenterFactory              = Container.Resolve <IPresenterFactory>();
            var synchronizationServiceManager = Container.Resolve <ISynchronizationServiceManager>();

            if (configurationManager.GetConfiguration().AlreadyInitialized)
            {
                if (configurationManager.GetConfiguration().ApplicationMode == ApplicationMode.Client)
                {
                    synchronizationServiceManager.StartSynchronizationService();
                }
                var loginPresenter = presenterFactory.Create <ILoginPresenter>();
                MainPage = new NavigationPage(loginPresenter.GetView() as Page);
            }
            else
            {
                var configPresenter = presenterFactory.Create <IConfigurationPresenter>();
                MainPage = new NavigationPage(configPresenter.GetView() as Page);
            }
        }
Ejemplo n.º 12
0
        public override void OnReceive(Context context, Intent intent)
        {
            Console.WriteLine($"Boot receiver started. Action: {intent.Action}");
            var containerFactory = new ContainerFactory();

            containerFactory.AddRegistrations(builder =>
            {
                var androidRegistrations = new AndroidPlatformServicesRegistrator();
                androidRegistrations.RegisterPlatformSpecificServices(builder);
            });

            var container            = containerFactory.Build();
            var configurationManager = container.Resolve <IMobileConfigurationReader>();

            if (configurationManager.GetConfiguration().AlreadyInitialized)
            {
                if (configurationManager.GetConfiguration().ApplicationMode == ApplicationMode.Client)
                {
                    var synchronizer = container.Resolve <ISynchronizationServiceManager>();
                    synchronizer.StartSynchronizationService();
                }
            }
        }
        protected override void OnHandleIntent(Intent intent)
        {
            try
            {
                Console.WriteLine("Service Started");
                var containerFactory = new ContainerFactory();
                containerFactory.AddRegistrations(builder =>
                {
                    var androidRegistrations = new AndroidPlatformServicesRegistrator();
                    androidRegistrations.RegisterPlatformSpecificServices(builder);
                });

                var container    = containerFactory.Build();
                var synchronizer = container.Resolve <ISynchronizer>();

                var serverOnline = synchronizer.Synchronize().Result;
                Console.WriteLine($"Service Synchronization Finished - Result: {serverOnline}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        public override async void PerformFetch(UIApplication application, Action <UIBackgroundFetchResult> completionHandler)
        {
            try
            {
                var containerFactory = new ContainerFactory();
                containerFactory.AddRegistrations(builder =>
                {
                    var iosRegistrations = new iOSPlatformServicesRegistrator();
                    iosRegistrations.RegisterPlatformSpecificServices(builder);
                });

                var container    = containerFactory.Build();
                var synchronizer = container.Resolve <ISynchronizer>();

                var serverOnline = await synchronizer.Synchronize();

                completionHandler(UIBackgroundFetchResult.NewData);
            }
            catch (Exception ex)
            {
                completionHandler(UIBackgroundFetchResult.Failed);
            }
        }
 public void Test()
 {
     var referencedAssembly = AssemblyCompiler.Compile(referencedCode);
     var assembly = AssemblyCompiler.Compile(code, referencedAssembly);
     var factory = new ContainerFactory().WithTypesFromAssemblies(new[] {assembly});
     using (var container = factory.Build())
     {
         var interfaceType = referencedAssembly.GetType("A1.ISomeInterface");
         Assert.That(container.Get(interfaceType).GetType().Name, Is.EqualTo("SomeInterfaceImpl"));
     }
 }
 public void Test()
 {
     var assembly = AssemblyCompiler.Compile(testCode);
     File.WriteAllText(configFileName, "A.parameter->11");
     var factory = new ContainerFactory()
         .WithAssembliesFilter(x => x.Name.StartsWith("tmp_"))
         .WithConfigFile(configFileName)
         .WithTypesFromAssemblies(new[] { assembly });
     var e = Assert.Throws<SimpleContainerException>(() => factory.Build());
     Assert.That(e.Message, Is.EqualTo("for name [A] more than one type found [A1.A], [A2.A]"));
 }
Ejemplo n.º 17
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     container = ContainerFactory.Build(logger);
     container.Resolve <MainWindow>().Show();
 }
Ejemplo n.º 18
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var loggerFactory = services.BuildServiceProvider().GetService <ILoggerFactory>();

            var logger = loggerFactory.CreateLogger(typeof(Startup));

            try
            {
                // Add framework services.
                services.AddMvc(
                    config =>
                {
                    if (Configuration.Authentication.RequireHttps)
                    {
                        config.Filters.Add(new RequireHttpsFilter());
                    }

                    config.Filters.Add(new AuthorizeFilter("AuthenticatedUser"));
                    config.Filters.Add(new ValidateActionParametersAttribute());
                    config.Filters.Add(new ValidateModelAttribute());

                    // add custom binder to beginning of collection
                    config.ModelBinderProviders.Insert(0, new ProfileFilterModelBinderProvider());
                }).AddJsonOptions(
                    options =>
                {
                    options.SerializerSettings.Converters.Add(
                        new StringEnumConverter
                    {
                        CamelCaseText = true
                    });
                    options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
                });

                services.AddMemoryCache();

                // The order in which middleware is configured and added is important
                services.AddAuthentication(o =>
                {
                    o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                    o.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                })
                .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme,
                              options => ConfigureAuthentication(logger, CurrentEnvironment, options));

                // Transform claims to ensure authenticated identity has AccountId claim and any possible Auth0 claims mapped
                services.AddTransient <IClaimsTransformation, ClaimsTransformer>();

                services.AddAuthorization(
                    options =>
                {
                    options.AddPolicy("AuthenticatedUser",
                                      policyBuilder => policyBuilder.RequireAuthenticatedUser());
                    options.AddPolicy(
                        Role.Administrator,
                        policyBuilder => policyBuilder.RequireRole(Role.Administrator));
                });

                services.Configure <FormOptions>(options =>
                {
                    options.MultipartBodyLengthLimit = Configuration.Photo.MaxLength;
                });

                services.AddCors();

                // Register the Swagger generator, defining one or more Swagger documents
                services.AddSwaggerGen(
                    c =>
                {
                    c.SwaggerDoc(
                        "v1",
                        new Info
                    {
                        Title   = "DevMentor API",
                        Version = "v1"
                    });
                    c.DescribeAllEnumsAsStrings();
                    c.DescribeAllParametersInCamelCase();
                    c.DescribeStringEnumsInCamelCase();

                    //var securityScheme = new OAuth2Scheme
                    //{
                    //    AuthorizationUrl = Configuration.Authentication.AuthorizationUrl,
                    //    Flow = "implicit",
                    //    TokenUrl = Configuration.Authentication.TokenUrl
                    //};

                    //c.AddSecurityDefinition("Auth02", securityScheme);

                    var filePath = Path.Combine(
                        PlatformServices.Default.Application.ApplicationBasePath,
                        "TechMentorApi.xml");
                    c.IncludeXmlComments(filePath);

                    c.OperationFilter <OAuth2OperationFilter>();
                    c.DocumentFilter <AdministratorDocumentFilter>();
                });

                ApplicationContainer = ContainerFactory.Build(services, Configuration);
            }
            catch (TypeInitializationException ex)
            {
                var eventId = new EventId(1);

                logger.LogError(eventId, ex, "Failed to configure services");

                var loaderFailure = ex.InnerException as ReflectionTypeLoadException;

                if (loaderFailure != null)
                {
                    foreach (var loaderException in loaderFailure.LoaderExceptions)
                    {
                        logger.LogError(eventId, loaderException, "Loader Exception in ConfigureServices");
                    }
                }

                throw;
            }
            catch (Exception ex)
            {
                var eventId = new EventId(2);

                logger.LogError(eventId, ex, "Failed to configure services");
            }

            // Create the IServiceProvider based on the container.
            return(new AutofacServiceProvider(ApplicationContainer));
        }
 public void Test()
 {
     var referencedAssembly = AssemblyCompiler.Compile(referencedCode);
     var a1 = AssemblyCompiler.Compile(code1, referencedAssembly);
     var a2 = AssemblyCompiler.Compile(code2, referencedAssembly);
     var factory = new ContainerFactory()
         .WithTypesFromAssemblies(new[] {a1, a2})
         .WithAssembliesFilter(x => x.Name == a2.GetName().Name);
     using (var container = factory.Build())
     {
         var interfaceType = referencedAssembly.GetType("A1.ISomeInterface");
         Assert.That(container.Get(interfaceType).GetType().Name, Is.EqualTo("TestClass2"));
     }
 }
Ejemplo n.º 20
0
 public static void AppInitialize()
 {
     _container = ContainerFactory.Build();
     AppDomain.CurrentDomain.DomainUnload += Shutdown;
 }