Exemplo n.º 1
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterType <ServicePointConfiguration>().SingleInstance();
            builder.RegisterType <ServerManager>().SingleInstance();
            builder.RegisterType <ActiveUrls>().As <IActiveUrls>().SingleInstance();
            builder.RegisterType <ApiAppVersion>().As <IApiAppVersion>().SingleInstance();
            builder.RegisterType <OsEnvironment>().As <IEnvironment>().SingleInstance();
            builder.RegisterType <SystemProcesses>().As <IOsProcesses>().SingleInstance();
            builder.Register(c =>
                             new SafeSystemNetworkInterfaces(
                                 c.Resolve <ILogger>(),
                                 new SystemNetworkInterfaces(
                                     c.Resolve <ILogger>())))
            .As <INetworkInterfaces>().SingleInstance();
            builder.RegisterType <HttpClients>().As <IHttpClients>().SingleInstance();
            builder.Register(c => Schedulers.FromApplicationDispatcher()).As <IScheduler>().SingleInstance();
            builder.Register(c => new TokenStorage(c.Resolve <UserSettings>())).As <ITokenStorage>().SingleInstance();

            builder.Register(c =>
                             new CertificateHandler(
                                 c.Resolve <Common.Configuration.Config>().TlsPinningConfig,
                                 c.Resolve <IReportClient>())).SingleInstance();

            builder.Register(c =>
                             new SafeDnsHandler(
                                 c.Resolve <IEventAggregator>(),
                                 c.Resolve <IDnsClient>())
            {
                InnerHandler = c.Resolve <CertificateHandler>()
            }).SingleInstance();

            builder.Register(c =>
                             new LoggingHandler(
                                 c.Resolve <ILogger>())
            {
                InnerHandler = c.Resolve <SafeDnsHandler>()
            });

            builder.Register(c =>
                             new RetryingHandler(
                                 c.Resolve <Common.Configuration.Config>().ApiTimeout,
                                 c.Resolve <Common.Configuration.Config>().ApiRetries,
                                 (retryCount, response, context) => new SleepDurationProvider(response, retryCount).Value())
            {
                InnerHandler = c.Resolve <LoggingHandler>()
            }).SingleInstance();

            builder.Register(c =>
                             new OutdatedAppHandler
            {
                InnerHandler = c.Resolve <RetryingHandler>()
            }).SingleInstance();

            builder.Register(c =>
                             new UnauthorizedResponseHandler(
                                 c.Resolve <ITokenClient>(),
                                 c.Resolve <ITokenStorage>())
            {
                InnerHandler = c.Resolve <OutdatedAppHandler>()
            }).SingleInstance();

            builder.Register(c =>
                             new CancellingHandler
            {
                InnerHandler = c.Resolve <UnauthorizedResponseHandler>()
            }).SingleInstance();

            builder.Register(c =>
                             new TokenClient(
                                 new HttpClient(c.Resolve <RetryingHandler>())
            {
                BaseAddress = c.Resolve <IActiveUrls>().ApiUrl.Uri
            },
                                 c.Resolve <IApiAppVersion>(),
                                 c.Resolve <ITokenStorage>(),
                                 c.Resolve <Common.Configuration.Config>().ApiVersion,
                                 TranslationSource.Instance.CurrentCulture.Name))
            .As <ITokenClient>()
            .SingleInstance();

            builder.Register(c =>
            {
                var certificateHandler = new CertificateHandler(
                    c.Resolve <Common.Configuration.Config>().TlsPinningConfig,
                    c.Resolve <IReportClient>());

                var safeDnsHandler = new SafeDnsHandler(
                    c.Resolve <IEventAggregator>(),
                    c.Resolve <IDnsClient>())
                {
                    InnerHandler = certificateHandler
                };

                var loggingHandler = new LoggingHandler(
                    c.Resolve <ILogger>())
                {
                    InnerHandler = safeDnsHandler
                };

                var retryingHandler = new RetryingHandler(
                    c.Resolve <Common.Configuration.Config>().ApiTimeout,
                    c.Resolve <Common.Configuration.Config>().ApiRetries,
                    (retryCount, response, context) => new SleepDurationProvider(response, retryCount).Value())
                {
                    InnerHandler = loggingHandler
                };

                return(new ApiClient(
                           new HttpClient(c.Resolve <CancellingHandler>())
                {
                    BaseAddress = c.Resolve <IActiveUrls>().ApiUrl.Uri
                },
                           new HttpClient(retryingHandler)
                {
                    BaseAddress = c.Resolve <IActiveUrls>().ApiUrl.Uri,
                    DefaultRequestHeaders = { ConnectionClose = true }
                },
                           c.Resolve <ILogger>(),
                           c.Resolve <ITokenStorage>(),
                           c.Resolve <IApiAppVersion>(),
                           c.Resolve <Common.Configuration.Config>().ApiVersion,
                           TranslationSource.Instance.CurrentCulture.Name));
            })
            .As <IApiClient>()
            .SingleInstance();

            builder.Register(c => new NLogLoggingConfiguration(c.Resolve <Common.Configuration.Config>().AppLogFolder, "app"))
            .AsSelf().SingleInstance();
            builder.RegisterType <NLogLoggerFactory>().As <ILoggerFactory>().SingleInstance();
            builder.Register(c => c.Resolve <ILoggerFactory>().Logger())
            .As <ILogger>().SingleInstance();
            builder.RegisterType <LogCleaner>().SingleInstance();

            builder.RegisterType <UpdateNotification>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <UpdateService>().AsSelf().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <ServiceClient>().SingleInstance();
            builder.RegisterType <UpdateEvents>().SingleInstance();

            builder.RegisterType <UserValidator>().SingleInstance();

            builder.Register(c => new UserAuth(
                                 c.Resolve <IApiClient>(),
                                 c.Resolve <ILogger>(),
                                 c.Resolve <IUserStorage>(),
                                 c.Resolve <ITokenStorage>())).SingleInstance();

            builder.RegisterType <NetworkClient>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <DnsClients>().As <IDnsClients>().SingleInstance();
            builder.Register(c =>
                             new SafeDnsClient(
                                 new DnsClient(
                                     c.Resolve <IDnsClients>(),
                                     c.Resolve <INetworkInterfaces>())))
            .As <IDnsClient>().SingleInstance();

            builder.Register(c =>
                             new CachingReportClient(
                                 new ReportClient(c.Resolve <IActiveUrls>().TlsReportUrl.Uri)))
            .As <IReportClient>()
            .SingleInstance();

            builder.RegisterType <EventClient>().SingleInstance();
            builder.RegisterType <UserInfoHandler>().AsImplementedInterfaces().SingleInstance();

            builder.RegisterType <VpnProfileHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <VpnCredentialProvider>().SingleInstance();
            builder.Register(c => new EventTimer(
                                 c.Resolve <EventClient>(),
                                 c.Resolve <Common.Configuration.Config>().EventCheckInterval))
            .AsSelf()
            .AsImplementedInterfaces()
            .SingleInstance();
            builder.Register(c => new Language.Language(c.Resolve <IAppSettings>()))
            .AsSelf()
            .AsImplementedInterfaces()
            .SingleInstance();
        }
Exemplo n.º 2
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterType<HumanVerifier>().As<IHumanVerifier>().SingleInstance();
            builder.RegisterType<ServicePointConfiguration>().SingleInstance();
            builder.RegisterType<ServerManager>().SingleInstance();
            builder.RegisterType<ActiveUrls>().As<IActiveUrls>().SingleInstance();
            builder.RegisterType<ApiAppVersion>().As<IApiAppVersion>().SingleInstance();
            builder.RegisterType<OsEnvironment>().As<IEnvironment>().SingleInstance();
            builder.RegisterType<SystemProcesses>().As<IOsProcesses>().SingleInstance();
            builder.Register(c => 
                    new SafeSystemNetworkInterfaces(c.Resolve<ILogger>(), new SystemNetworkInterfaces()))
                .As<INetworkInterfaces>().SingleInstance();
            builder.RegisterType<NetworkInterfaceLoader>().As<INetworkInterfaceLoader>().SingleInstance();
            builder.RegisterType<HttpClients>().As<IHttpClients>().SingleInstance();
            builder.Register(c => Schedulers.FromApplicationDispatcher()).As<IScheduler>().SingleInstance();
            builder.Register(c => new TokenStorage(c.Resolve<UserSettings>())).As<ITokenStorage>().SingleInstance();

            builder.Register(c =>
                new CertificateHandler(
                    c.Resolve<Common.Configuration.Config>().TlsPinningConfig,
                    c.Resolve<IReportClient>())).SingleInstance();

            builder.Register(c => 
                new SafeDnsHandler(
                        c.Resolve<IEventAggregator>(),
                        c.Resolve<IDnsClient>())
                    { InnerHandler = c.Resolve<CertificateHandler>() }).SingleInstance();

            builder.Register(c =>
                new LoggingHandler(
                        c.Resolve<ILogger>())
                    {InnerHandler = c.Resolve<SafeDnsHandler>()});

            builder.Register(c =>
                new RetryingHandler(
                        c.Resolve<Common.Configuration.Config>().ApiTimeout,
                        c.Resolve<Common.Configuration.Config>().ApiUploadTimeout,
                        c.Resolve<Common.Configuration.Config>().ApiRetries,
                        (retryCount, response, context) => new SleepDurationProvider(response).Value())
                    {InnerHandler = c.Resolve<LoggingHandler>()}).SingleInstance();

            builder.Register(c =>
                new OutdatedAppHandler
                    {InnerHandler = c.Resolve<RetryingHandler>()}).SingleInstance();

            builder.Register(c =>
                new HumanVerificationHandler(c.Resolve<IHumanVerifier>(), WebViewConfig.IsWebViewSupported())
                    {InnerHandler = c.Resolve<OutdatedAppHandler>()}).SingleInstance();

            builder.Register(c =>
                new UnauthorizedResponseHandler(
                        c.Resolve<ITokenClient>(),
                        c.Resolve<ITokenStorage>(),
                        c.Resolve<IUserStorage>(),
                        c.Resolve<ILogger>())
                    {InnerHandler = c.Resolve<HumanVerificationHandler>()}).SingleInstance();

            builder.Register(c =>
                new CancellingHandler
                    {InnerHandler = c.Resolve<UnauthorizedResponseHandler>()}).SingleInstance();

            builder.Register(c =>
                new AlternativeHostHandler(
                    c.Resolve<ILogger>(),
                    c.Resolve<DohClients>(),
                    c.Resolve<MainHostname>(),
                    c.Resolve<IAppSettings>(),
                    c.Resolve<GuestHoleState>(),
                    new Uri(c.Resolve<Common.Configuration.Config>().Urls.ApiUrl).Host)
                {
                    InnerHandler = c.Resolve<CancellingHandler>()
                }).SingleInstance();

            builder.Register(c =>
                    new TokenClient(
                        c.Resolve<ILogger>(),
                        new HttpClient(c.Resolve<RetryingHandler>())
                            {BaseAddress = c.Resolve<IActiveUrls>().ApiUrl.Uri},
                        c.Resolve<IApiAppVersion>(),
                        c.Resolve<ITokenStorage>(),
                        c.Resolve<Common.Configuration.Config>().ApiVersion,
                        TranslationSource.Instance.CurrentCulture.Name))
                .As<ITokenClient>()
                .SingleInstance();

            builder.Register(c =>
                {
                    var certificateHandler = new CertificateHandler(
                        c.Resolve<Common.Configuration.Config>().TlsPinningConfig,
                        c.Resolve<IReportClient>());

                    var safeDnsHandler = new SafeDnsHandler(
                            c.Resolve<IEventAggregator>(),
                            c.Resolve<IDnsClient>())
                        {InnerHandler = certificateHandler};

                    var loggingHandler = new LoggingHandler(
                            c.Resolve<ILogger>())
                        {InnerHandler = safeDnsHandler};

                    var retryingHandler = new RetryingHandler(
                            c.Resolve<Common.Configuration.Config>().ApiTimeout,
                            c.Resolve<Common.Configuration.Config>().ApiUploadTimeout,
                            c.Resolve<Common.Configuration.Config>().ApiRetries,
                            (retryCount, response, context) => new SleepDurationProvider(response).Value())
                        {InnerHandler = loggingHandler};

                    var alternativeHostHandler = new AlternativeHostHandler(
                            c.Resolve<ILogger>(),
                            c.Resolve<DohClients>(),
                            c.Resolve<MainHostname>(),
                            c.Resolve<IAppSettings>(),
                            c.Resolve<GuestHoleState>(),
                            new Uri(c.Resolve<Common.Configuration.Config>().Urls.ApiUrl).Host)
                    { InnerHandler = retryingHandler};

                    return new ApiClient(
                        new HttpClient(c.Resolve<AlternativeHostHandler>())
                        {
                            BaseAddress = c.Resolve<IActiveUrls>().ApiUrl.Uri
                        },
                        new HttpClient(alternativeHostHandler)
                        {
                            BaseAddress = c.Resolve<IActiveUrls>().ApiUrl.Uri,
                            DefaultRequestHeaders = { ConnectionClose = true }
                        },
                        c.Resolve<ILogger>(),
                        c.Resolve<ITokenStorage>(),
                        c.Resolve<IApiAppVersion>(),
                        c.Resolve<Common.Configuration.Config>().ApiVersion,
                        TranslationSource.Instance.CurrentCulture.Name);
                })
                .As<IApiClient>()
                .SingleInstance();

            builder.RegisterType<ActionableFailureApiResultEventHandler>().SingleInstance();

            builder.RegisterType<Log4NetLoggerFactory>().As<ILoggerFactory>().SingleInstance();
            builder.Register(c => c.Resolve<ILoggerFactory>().Get(c.Resolve<Common.Configuration.Config>().AppLogDefaultFullFilePath))
                .As<ILogger>().SingleInstance();
            builder.RegisterType<LogCleaner>().SingleInstance();
            builder.RegisterType<UpdateService>().AsSelf().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<ServiceClient>().SingleInstance();
            builder.RegisterType<UpdateEvents>().SingleInstance();

            builder.RegisterType<UserValidator>().SingleInstance();

            builder.Register(c => new UserAuth(
                c.Resolve<IApiClient>(),
                c.Resolve<ILogger>(),
                c.Resolve<IUserStorage>(),
                c.Resolve<ITokenStorage>(),
                c.Resolve<IAuthCertificateManager>())).SingleInstance();

            builder.RegisterType<NetworkClient>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<DnsClients>().As<IDnsClients>().SingleInstance();
            builder.Register(c =>
                    new SafeDnsClient(
                        new DnsClient(
                            c.Resolve<IDnsClients>(),
                            c.Resolve<INetworkInterfaces>())))
                .As<IDnsClient>().SingleInstance();

            builder.Register(c =>
                    new CachingReportClient(
                        new ReportClient(c.Resolve<IActiveUrls>().TlsReportUrl.Uri)))
                .As<IReportClient>()
                .SingleInstance();

            builder.RegisterType<EventClient>().SingleInstance();
            builder.RegisterType<UserInfoHandler>().AsImplementedInterfaces().SingleInstance();

            builder.RegisterType<VpnProfileHandler>().AsImplementedInterfaces().SingleInstance();
            builder.RegisterType<VpnCredentialProvider>().As<IVpnCredentialProvider>().SingleInstance();
            builder.Register(c => new EventTimer(
                    c.Resolve<EventClient>(),
                    c.Resolve<Common.Configuration.Config>().EventCheckInterval.RandomizedWithDeviation(0.2))) 
                .AsSelf()
                .AsImplementedInterfaces()
                .SingleInstance();
            builder.Register(c => new SafeSystemProxy(c.Resolve<ILogger>(), new SystemProxy()))
                .AsImplementedInterfaces()
                .SingleInstance();
            builder.Register(c => new MainHostname(c.Resolve<Common.Configuration.Config>().Urls.ApiUrl)).SingleInstance();
            builder.Register(c => new DohClients(
                c.Resolve<Common.Configuration.Config>().DoHProviders,
                c.Resolve<Common.Configuration.Config>().DohClientTimeout))
                .SingleInstance();
            builder.RegisterType<UnhandledExceptionLogging>().SingleInstance();
            builder.RegisterType<MainWindowState>().As<IMainWindowState>().SingleInstance();
            builder.RegisterType<SingleActionFactory>().As<ISingleActionFactory>().SingleInstance();
            builder.RegisterType<LastServerLoadTimeProvider>().As<ILastServerLoadTimeProvider>().SingleInstance();
            builder.RegisterType<ClientConfig>().AsImplementedInterfaces().SingleInstance();
            builder.Register(c => new AnnouncementService(
                c.Resolve<IAppSettings>(),
                c.Resolve<IScheduler>(),
                c.Resolve<IApiClient>(),
                c.Resolve<IAnnouncementCache>(),
                c.Resolve<Common.Configuration.Config>().AnnouncementUpdateInterval))
                .AsImplementedInterfaces()
                .SingleInstance();
            builder.RegisterType<AnnouncementCache>().As<IAnnouncementCache>().SingleInstance();
            builder.Register(c =>
                    new NtpClient(c.Resolve<Common.Configuration.Config>().NtpServerUrl, c.Resolve<ILogger>()))
                .As<INtpClient>().SingleInstance();
        }