Exemple #1
0
        public static WireUp UsrDapper(this WireUp wireUp)
        {
            //注册DataProvider
            wireUp.ContainerBuilder.RegisterType <IdentityUserProvider>().As <IIdentityUserProvider>().InstancePerLifetimeScope();

            return(wireUp);
        }
Exemple #2
0
        public static WireUp UseAutoFacMvc(this WireUp wireUp)
        {
            var builder = wireUp.ContainerBuilder;

            // Register your MVC controllers. (MvcApplication is the name of
            // the class in Global.asax.)
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(typeof(MvcApplication).Assembly);
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule <AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();


            // OPTIONAL: Enable action method parameter injection (RARE).
            //builder.InjectActionInvoker();
            // Set the dependency resolver to be Autofac.
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            return(wireUp);
        }
Exemple #3
0
        public async Task When_Only_Google_Enabled()
        {
            const string detectedLanguage = "en";
            const string english          = "City";
            const string turkish          = "sehir";
            const string result           = "* sehir\r\n";

            var notifier         = A.Fake <INotifier>();
            var googleAnalytics  = A.Fake <IGoogleAnalyticsTracker>();
            var languageDetector = A.Fake <IGoogleLanguageDetector>();
            var resultOrganizer  = A.Fake <ResultOrganizer>();
            var translator       = A.Fake <ITranslator>();
            CancellationToken cancellationToken = CancellationToken.None;

            A.CallTo(() => languageDetector.DetectLanguage(english, A <CancellationToken> .Ignored))
            .Returns(detectedLanguage);
            A.CallTo(() => translator.Translate(A <TranslateRequest> .Ignored, cancellationToken))
            .Returns(new TranslateResult(true, turkish));
            A.CallTo(() => translator.Type).Returns(TranslatorType.Google);

            var activeTranslatorConfiguration = new ActiveTranslatorConfiguration();

            activeTranslatorConfiguration.AddTranslator(TranslatorType.Google);
            activeTranslatorConfiguration.Activate(TranslatorType.Google);

            var wireUp = new WireUp(
                builder =>
            {
                builder.AddInMemoryCollection(new[]
                {
                    new KeyValuePair <string, string>("ToLanguage", "Turkish"),
                    new KeyValuePair <string, string>("FromLanguage", "English")
                });
            }, services =>
            {
                services.RemoveAll <ITranslator>();
                services.AddTransient <IFinder, Finder>();
                services.AddTransient(sp => notifier);
                services.AddTransient(sp => googleAnalytics);
                services.AddTransient(sp => languageDetector);
                services.AddTransient(sp => activeTranslatorConfiguration);
                services.AddTransient(sp => resultOrganizer);
                services.AddSingleton(sp => translator);
            })
            {
                MessageHandler = GoogleMessageHandler()
            };

            var sut = wireUp.ServiceProvider.GetService <IFinder>();
            await sut.Find(english, cancellationToken);

            A.CallTo(() => notifier.AddNotification(english, ImageUrls.NotificationUrl, result))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => translator.Translate(A <TranslateRequest> .Ignored, A <CancellationToken> .Ignored))
            .MustHaveHappenedOnceExactly();
        }
Exemple #4
0
        public EventAutoWire(int id, Type[] types)
        {
            ID                = id;
            Types             = types;
            _genericSubscribe = _eventSubscribeMethods[types.Length];
            if (types.Length > 0)
            {
                _genericSubscribe = _genericSubscribe.MakeGenericMethod(Types);
            }

            _wireUp = Build();
        }
Exemple #5
0
        protected override void OnStartup(StartupEventArgs eventArgs)
        {
            this.wireUp = new WireUp(postConfigureServices: services =>
            {
                services.AddSingleton <Notifications>();
                services.AddTransient <IClipboardManager, ClipboardManager>();
                services.AddSingleton <GrowlNotifications>();
                services.AddTransient <TranslatorBootstrapper>();
                services.AddTransient <INotifier, GrowlNotifier>();
                services.AddSingleton <MainWindow>();
            });

            DispatcherUnhandledException += OnDispatcherUnhandledException;
            var mainWindow = this.wireUp.ServiceProvider.GetRequiredService <MainWindow>();

            mainWindow.Closed += (sender, args) => { Current.Shutdown(0); };
            mainWindow.InitializeComponent();
            mainWindow.Show();
        }
Exemple #6
0
        public static WireUp RegisterService(this WireUp wireUp)
        {
            wireUp.ContainerBuilder.RegisterType <SignInService>().As <ISignInService>().InstancePerLifetimeScope();

            return(wireUp);
        }
Exemple #7
0
 public static WireUp WormUpModel(this WireUp wireUp)
 {
     return(wireUp);
 }
 public static WireUp UseAutofac(this WireUp configuration)
 {
     return(UseAutofac(configuration, new ContainerBuilder()));
 }
 /// <summary>Use Autofac as the object container.
 /// </summary>
 /// <returns></returns>
 public static WireUp UseAutofac(this WireUp configuration, ContainerBuilder containerBuilder)
 {
     ObjectContainer.SetContainer(new AutofacContainer(containerBuilder));
     return(configuration);
 }
Exemple #10
0
 public static WireUp UseLog4Net(this WireUp configuration, string configFile = "log4net.config")
 {
     ObjectContainer.Current.RegisterInstance <ILoggerFactory, Log4NetLoggerFactory>(
         new Log4NetLoggerFactory(configFile));
     return(configuration);
 }