Esempio n. 1
0
        public void Register_ImplementationTypeProvided_InterfaceResolved()
        {
            SimpleInjector simpleInjector = new SimpleInjector();

            simpleInjector.Register <ITestClass, TestClass>();

            Assert.IsNotNull(simpleInjector.Resolve <ITestClass>());
        }
Esempio n. 2
0
        public void Constructor_InjectorWithImplementationMapProvided_ImplementationMapCopied()
        {
            SimpleInjector simpleInjector = new SimpleInjector();

            simpleInjector.Register <ITestClass, TestClass>();

            SimpleInjector simpleInjectorCopy = new SimpleInjector(simpleInjector);

            Assert.IsNotNull(simpleInjectorCopy.Resolve <ITestClass>());
        }
Esempio n. 3
0
        public void Resolve_ClassHasRegisteredSetterDependency_DependencyResolved()
        {
            SimpleInjector simpleInjector = new SimpleInjector();

            simpleInjector.Register <ITestClass, TestClass>();

            TestClassSetter result = simpleInjector.Resolve <TestClassSetter>();

            Assert.IsNotNull(result);
        }
Esempio n. 4
0
        private static void SampleCommandHandler()
        {
            var injector = new SimpleInjector();

            injector.Register <ICommandHandler <TestCommand> >(() => new ConsoleLogHandler());

            var commandBus = new CommandBus(injector);

            commandBus.Register <TestCommand, ICommandHandler <TestCommand> >();

            var command = new TestCommand("srnlib");

            commandBus.Handle(command);
        }
 public void RegisterServices(SimpleInjector.Container container)
 {
     container.Register<ThemeService>();
     container.Register<ICartService, CartService>();
     container.Register<IPageService, PageService>();
     container.Register<ITaxService, TaxService>();
     container.Register<IShippingService, ShippingService>();
     container.Register<IProductService, ProductService>();
 }
Esempio n. 6
0
        private static void SampleQueryHandler()
        {
            var injector = new SimpleInjector();

            injector.Register <IQueryHandler <TestQuery, TestResponse> >(() => new TestQueryHandler());

            var queryBus = new QueryBus(injector);

            queryBus.Register <TestQuery, IQueryHandler <TestQuery, TestResponse> >();

            var query    = new TestQuery("srn");
            var response = queryBus.Handle(query);

            Console.WriteLine(response.Message);
        }
        public static void RegisterServices(SimpleInjector.Container container)
        {
            container.Register<ApplicationUserContext>(Lifestyle.Scoped);
            container.RegisterPerWebRequest<IUserStore<ApplicationUser>>(() => new UserStore<ApplicationUser>(new ApplicationUserContext()));

            container.Register<ApplicationUserManager>(Lifestyle.Scoped);
            container.Register<ApplicationSignInManager>(Lifestyle.Scoped);

            container.Register<ITransportadoraAppService, TransportadoraAppService>();
            container.Register<ITransportadoraService, TransportadoraService>();
            container.Register<ITransportadoraRepository, TransportadoraRepository>();

            container.Register<IDbContext, TesteAxadoContext>();
        }
Esempio n. 8
0
 private static void InitializeContainer(Container container)
 {
     SimpleInjector.Register(container);
 }
		protected override void RegisterPlatformSpecificImplementations (SimpleInjector.Container container)
		{
			container.Register<ISettingsService, SettingsService>();
			container.Register<IDisplayAlertService, DisplayAlertService> ();
		}
Esempio n. 10
0
        /// <summary>
        ///   Loads the module into the kernel.
        /// </summary>
        public void RegisterComponents(SimpleInjector.Container container)
        {
            IConfiguration configuration = new Configuration();
            container.Register<IConfiguration>(() => configuration, Lifestyle.Singleton);

            Lazy<GallerySetting> gallerySetting = new Lazy<GallerySetting>(() =>
            {
                using (var entitiesContext = new EntitiesContext())
                {
                    var settingsRepo = new EntityRepository<GallerySetting>(entitiesContext);
                    return settingsRepo.GetAll().FirstOrDefault();
                }
            });

            container.Register<GallerySetting>(()=> gallerySetting.Value);
            //Bind<GallerySetting>().ToMethod(c => gallerySetting.Value);

            container.RegisterPerWebRequest<ISearchService, LuceneSearchService>();

            container.RegisterPerWebRequest<IEntitiesContext>(() => new EntitiesContext());
            container.RegisterPerWebRequest<IEntityRepository<User>, EntityRepository<User>>();
            container.RegisterPerWebRequest<IEntityRepository<PackageRegistration>, EntityRepository<PackageRegistration>>();
            container.RegisterPerWebRequest<IEntityRepository<Package>, EntityRepository<Package>>();
            container.RegisterPerWebRequest<IEntityRepository<PackageAuthor>, EntityRepository<PackageAuthor>>();
            container.RegisterPerWebRequest<IEntityRepository<PackageFramework>, EntityRepository<PackageFramework>>();
            container.RegisterPerWebRequest<IEntityRepository<PackageDependency>, EntityRepository<PackageDependency>>();
            container.RegisterPerWebRequest<IEntityRepository<PackageFile>, EntityRepository<PackageFile>>();
            container.RegisterPerWebRequest<IEntityRepository<PackageStatistics>, EntityRepository<PackageStatistics>>();
            container.RegisterPerWebRequest<IEntityRepository<PackageOwnerRequest>, EntityRepository<PackageOwnerRequest>>();

            container.RegisterPerWebRequest<IUserService, UserService>();
            container.RegisterPerWebRequest<IPackageService, PackageService>();
            container.RegisterPerWebRequest<ICryptographyService, CryptographyService>();

            container.Register<IFormsAuthenticationService, FormsAuthenticationService>(Lifestyle.Singleton);

            container.RegisterPerWebRequest<IControllerFactory, NuGetControllerFactory>();
            container.RegisterPerWebRequest<IIndexingService, LuceneIndexingService>();
            container.RegisterPerWebRequest<INuGetExeDownloaderService, NuGetExeDownloaderService>();

            Lazy<IMailSender> mailSenderThunk = new Lazy<IMailSender>(() =>
            {
                var settings = container.GetInstance<GallerySetting>();
                if (settings.UseSmtp)
                {
                    var mailSenderConfiguration = new MailSenderConfiguration()
                    {
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        Host = settings.SmtpHost,
                        Port = settings.SmtpPort,
                        EnableSsl = configuration.SmtpEnableSsl,
                    };

                    if (!String.IsNullOrWhiteSpace(settings.SmtpUsername))
                    {
                        mailSenderConfiguration.UseDefaultCredentials = false;
                        mailSenderConfiguration.Credentials = new NetworkCredential(
                            settings.SmtpUsername,
                            settings.SmtpPassword);
                    }

                    return new NuGetGallery.MailSender(mailSenderConfiguration);
                }
                else
                {
                    var mailSenderConfiguration = new MailSenderConfiguration()
                    {
                        DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory,
                        PickupDirectoryLocation = HostingEnvironment.MapPath("~/App_Data/Mail")
                    };

                    return new NuGetGallery.MailSender(mailSenderConfiguration);
                }
            });

            container.Register<IMailSender>(()=> mailSenderThunk.Value,Lifestyle.Singleton);

            container.Register<IMessageService, MessageService>(Lifestyle.Singleton);

            container.RegisterPerWebRequest<IPrincipal>(() => HttpContext.Current.User);
            //Bind<IPrincipal>().ToMethod(context => HttpContext.Current.User);

            switch (configuration.PackageStoreType)
            {
                case PackageStoreType.FileSystem:
                case PackageStoreType.NotSpecified:
                    container.Register<IFileSystemService, FileSystemService>(Lifestyle.Singleton);
                    container.Register<IFileStorageService, FileSystemFileStorageService>(Lifestyle.Singleton);
                    break;
                case PackageStoreType.AzureStorageBlob:
                    container.Register<ICloudBlobClient>(() => new CloudBlobClientWrapper(new CloudBlobClient(
                            new Uri(configuration.AzureStorageBlobUrl, UriKind.Absolute),
                            new StorageCredentialsAccountAndKey(configuration.AzureStorageAccountName, configuration.AzureStorageAccessKey)
                            ))
                        ,Lifestyle.Singleton);
                    container.Register<IFileStorageService, CloudBlobFileStorageService>(Lifestyle.Singleton);
                    break;
                case PackageStoreType.AmazonS3Storage:
                    container.Register<IAmazonS3Client, AmazonS3ClientWrapper>(Lifestyle.Singleton);
                    container.Register<IFileStorageService, AmazonS3FileStorageService>(Lifestyle.Singleton);
                    break;
            }

            container.Register<IPackageFileService, PackageFileService>(Lifestyle.Singleton);
            container.Register<IUploadFileService, UploadFileService>();

            // todo: bind all package curators by convention
            container.Register<IAutomaticPackageCurator, WebMatrixPackageCurator>(Lifestyle.Singleton);
            container.Register<IAutomaticPackageCurator, Windows8PackageCurator>(Lifestyle.Singleton);

            // todo: bind all commands by convention
            container.RegisterPerWebRequest<IAutomaticallyCuratePackageCommand, AutomaticallyCuratePackageCommand>();
            container.RegisterPerWebRequest<ICreateCuratedPackageCommand, CreateCuratedPackageCommand>();
            container.RegisterPerWebRequest<IDeleteCuratedPackageCommand, DeleteCuratedPackageCommand>();
            container.RegisterPerWebRequest<IModifyCuratedPackageCommand, ModifyCuratedPackageCommand>();

            // todo: bind all queries by convention
            container.RegisterPerWebRequest<ICuratedFeedByKeyQuery, CuratedFeedByKeyQuery>();
            container.RegisterPerWebRequest<ICuratedFeedByNameQuery, CuratedFeedByNameQuery>();
            container.RegisterPerWebRequest<ICuratedFeedsByManagerQuery, CuratedFeedsByManagerQuery>();
            container.RegisterPerWebRequest<IPackageRegistrationByKeyQuery, PackageRegistrationByKeyQuery>();
            container.RegisterPerWebRequest<IPackageRegistrationByIdQuery, PackageRegistrationByIdQuery>();
            container.RegisterPerWebRequest<IUserByUsernameQuery, UserByUsernameQuery>();
            container.RegisterPerWebRequest<IPackageIdsQuery, PackageIdsQuery>();
            container.RegisterPerWebRequest<IPackageVersionsQuery, PackageVersionsQuery>();

            container.RegisterPerWebRequest<IAggregateStatsService, AggregateStatsService>();

            RegisterChocolateySpecific(container);
        }
 internal static void InsertIn(SimpleInjector.Container c)
 {
     c.Register<SheetEntryRepository>();
                     c.Register<CategoryRepository>();
                     c.Register<SheetRepository>();
                     c.Register<AppOwnerRepository>();
 }
Esempio n. 12
0
 private static void RegistriereImplementierungenZuInterfaces(SimpleInjector.Container container, Queue<Assembly> implementationAssemblies, HashSet<Type> interfaces)
 {
     var interfaceByNameComparer = new CrossCutting.SFW.EqualityComparerDefault<Type>((left, right) => left.Name == right.Name);
     foreach (var impl in implementationAssemblies)
     {
         var exportedTypesWithInterfaces = impl.GetExportedTypes().Where(a => a.GetInterfaces().Any());
         foreach (var etwi in exportedTypesWithInterfaces)
         {
             foreach (var iface in etwi.GetInterfaces().Where(i => interfaces.Contains(i, interfaceByNameComparer)))
             {
                 Lifestyle registerAsLifestyle = null;
                 if (iface.IsDefined(typeof(DIAsTransientAttribute)))
                 {
                     registerAsLifestyle = Lifestyle.Transient;
                 }
                 else if (iface.IsDefined(typeof(DIAsSingletonAttribute)))
                 {
                     registerAsLifestyle = Lifestyle.Singleton;
                 }
                 else
                 {
                     // unser Standardverhalten, wenn gar nichts angegeben ist, ist "Singleton",
                     // weil das bei meiner Implementierung 95% der Fälle abdeckt
                     registerAsLifestyle = Lifestyle.Singleton;
                 }
                 container.Register(iface, etwi, registerAsLifestyle);
             }
         }
     }
 }