Esempio n. 1
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Classes.FromThisAssembly()
                               .BasedOn <IController>()
                               .LifestyleTransient());

            container.Register(

                Component.For <IQueryableUnitOfWork, UnitOfWork>().ImplementedBy <UnitOfWork>(),

                Component.For <IProfileRepository, ProfileRepository>().ImplementedBy <ProfileRepository>(),

                Component.For <IAddressRepository, AddressRepository>().ImplementedBy <AddressRepository>(),

                Component.For <IAddressTypeRepository, AddressTypeRepository>().ImplementedBy <AddressTypeRepository>(),

                Component.For <IPhoneTypeRepository, PhoneTypeRepository>().ImplementedBy <PhoneTypeRepository>(),

                Component.For <IPhoneRepository, PhoneRepository>().ImplementedBy <PhoneRepository>(),

                Component.For <IProfileAddressRepository, ProfileAddressRepository>().ImplementedBy <ProfileAddressRepository>(),

                Component.For <IProfilePhoneRepository, ProfilePhoneRepository>().ImplementedBy <ProfilePhoneRepository>().LifestyleSingleton(),

                Component.For <IContactManager>().ImplementedBy <ContactManager>(),

                AllTypes.FromThisAssembly().BasedOn <IHttpController>().LifestyleTransient()

                )
            .AddFacility <LoggingFacility>(f => f.UseLog4Net());

            LoggerFactory.SetCurrent(new TraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
        }
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Classes.FromThisAssembly().
                               BasedOn <ApiController>().LifestyleTransient());
            container.Register(Classes.FromThisAssembly()
                               .BasedOn <IController>()
                               .LifestyleTransient());
            container.Register(
                Component.For <IQueryableUnitOfWork, UnitOfWork>().ImplementedBy <UnitOfWork>().LifestylePerWebRequest(),
                Component.For <ILogger, TraceSourceLog>().ImplementedBy <TraceSourceLog>().LifestyleSingleton(),
                Component.For <IEntityTranslatorService, EntityTranslatorService>().ImplementedBy <EntityTranslatorService>().LifestyleSingleton(),
                Component.For <ILookupTypeRepository, LookupTypeRepository>().ImplementedBy <LookupTypeRepository>().LifestyleTransient(),
                Component.For <ILookupRepository, LookupRepository>().ImplementedBy <LookupRepository>().LifestyleTransient(),
                Component.For <ILookupViewRepository, LookupViewRepository>().ImplementedBy <LookupViewRepository>().LifestyleTransient(),
                Component.For <IUserRepository, UserRepository>().ImplementedBy <UserRepository>().LifestyleTransient(),
                Component.For <IPropertyUserRepository, PropertyUserRepository>().ImplementedBy <PropertyUserRepository>().LifestyleTransient(),
                Component.For <IPropertyRepository, PropertyRepository>().ImplementedBy <PropertyRepository>().LifestyleTransient(),
                Component.For <IPropertyFacilityRepository, PropertyFacilityRepository>().ImplementedBy <PropertyFacilityRepository>().LifestyleTransient(),
                Component.For <IPropertyDetailsViewRepository, PropertyDetailsViewRepository>().ImplementedBy <PropertyDetailsViewRepository>().LifestyleTransient(),
                Component.For <IRoomRepository, RoomRepository>().ImplementedBy <RoomRepository>().LifestyleTransient(),
                Component.For <IRoomFacilityRepository, RoomFacilityRepository>().ImplementedBy <RoomFacilityRepository>().LifestyleTransient(),
                Component.For <IRoomTariffRepository, RoomTariffRepository>().ImplementedBy <RoomTariffRepository>().LifestyleTransient(),
                Component.For <IRoomDetailsViewRepository, RoomDetailsViewRepository>().ImplementedBy <RoomDetailsViewRepository>().LifestyleTransient()

                );
            //.AddFacility<LoggingFacility>(f => f.UseLog4Net());


            LoggerFactory.SetCurrent(new TraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            IEntityTranslatorService translatorService = container.Kernel.Resolve <IEntityTranslatorService>();

            RegisterTranslators(translatorService);
        }
Esempio n. 3
0
 /// <summary>
 /// Createt a new <paramref name="Microsoft.Samples.NLayerApp.Infrastructure.Crosscutting.Logging.ILog"/>
 /// </summary>
 /// <returns>Created ILog</returns>
 public static IEntityValidator CreateValidator()
 {
     if (_factory == null)
     {
         EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
     }
     return((_factory != null) ? _factory.Create() : null);
 }
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Classes.FromThisAssembly()
                               .BasedOn <IController>()
                               .LifestyleTransient());

            container.Register(
                Component.For <IQueryableUnitOfWork, UnitOfWork>().ImplementedBy <UnitOfWork>().LifeStyle.Transient,
                Component.For <IUserRepository, UserRepository>().ImplementedBy <UserRepository>().LifeStyle.Transient,
                Component.For <IFeedbackRepository, FeedbackRepository>().ImplementedBy <FeedbackRepository>().LifeStyle.Transient,
                Component.For <IFbDocumentRepository, FbDocumentRepository>().ImplementedBy <FbDocumentRepository>().LifeStyle.Transient,
                Component.For <IReservationRepository, ReservationRepository>().ImplementedBy <ReservationRepository>().LifeStyle.Transient,
                Component.For <INewsRepository, NewsRepository>().ImplementedBy <NewsRepository>().LifeStyle.Transient,
                Component.For <IArticleRepository, ArticleRepository>().ImplementedBy <ArticleRepository>().LifeStyle.Transient,
                Component.For <IPhotoRepository, PhotoRepository>().ImplementedBy <PhotoRepository>().LifeStyle.Transient,
                Component.For <IAtlasRepository, AtlasRepository>().ImplementedBy <AtlasRepository>().LifeStyle.Transient,
                Component.For <IBookRepository, BookRepository>().ImplementedBy <BookRepository>().LifeStyle.Transient,
                Component.For <IVideoRepository, AtlasRepository>().ImplementedBy <VideoRepository>().LifeStyle.Transient,
                Component.For <INewsCommentRepository, NewsCommentRepository>().ImplementedBy <NewsCommentRepository>().LifeStyle.Transient,
                Component.For <IArticleCommentRepository, ArticleCommentRepository>().ImplementedBy <ArticleCommentRepository>().LifeStyle.Transient,
                Component.For <IBookCommentRepository, BookCommentRepository>().ImplementedBy <BookCommentRepository>().LifeStyle.Transient,
                Component.For <IVideoCommentRepository, VideoCommentRepository>().ImplementedBy <VideoCommentRepository>().LifeStyle.Transient,
                Component.For <ISuggestionRepository, SuggestionRepository>().ImplementedBy <SuggestionRepository>().LifeStyle.Transient,
                Component.For <IRecentActivityRepository, RecentActivityRepository>().ImplementedBy <RecentActivityRepository>().LifeStyle.Transient,
                Component.For <ILogRepository, LogRepository>().ImplementedBy <LogRepository>().LifeStyle.Transient,
                Component.For <ILoginLogRepository, LoginLogRepository>().ImplementedBy <LoginLogRepository>().LifeStyle.Transient,
                Component.For <IMessageRepository, MessageRepository>().ImplementedBy <MessageRepository>().LifeStyle.Transient,
                Component.For <IMyMessageRepository, MyMessageRepository>().ImplementedBy <MyMessageRepository>().LifeStyle.Transient,
                Component.For <ITagRepository, TagRepository>().ImplementedBy <TagRepository>().LifeStyle.Transient,

                Component.For <IUserService>().ImplementedBy <UserService>().LifeStyle.Transient,
                Component.For <IFeedbackService>().ImplementedBy <FeedbackService>().LifeStyle.Transient,
                Component.For <IFbDocumentService>().ImplementedBy <FbDocumentService>().LifeStyle.Transient,
                Component.For <IReservationService>().ImplementedBy <ReservationService>().LifeStyle.Transient,
                Component.For <INewsService>().ImplementedBy <NewsService>().LifeStyle.Transient,
                Component.For <IArticleService>().ImplementedBy <ArticleService>().LifeStyle.Transient,
                Component.For <IPhotoService>().ImplementedBy <PhotoService>().LifeStyle.Transient,
                Component.For <IAtlasService>().ImplementedBy <AtlasService>().LifeStyle.Transient,
                Component.For <IBookService>().ImplementedBy <BookService>().LifeStyle.Transient,
                Component.For <IVideoService>().ImplementedBy <VideoService>().LifeStyle.Transient,
                Component.For <ICommentService>().ImplementedBy <CommentService>().LifeStyle.Transient,
                Component.For <ISuggestionService>().ImplementedBy <SuggestionService>().LifeStyle.Transient,
                Component.For <IRecentActivityService>().ImplementedBy <RecentActivityService>().LifeStyle.Transient,
                Component.For <ILoginLogService>().ImplementedBy <LoginLogService>().LifeStyle.Transient,
                Component.For <ILogService>().ImplementedBy <LogService>().LifeStyle.Transient,
                Component.For <IMessageService>().ImplementedBy <MessageService>().LifeStyle.Transient,
                Component.For <IMyMessageService>().ImplementedBy <MyMessageService>().LifeStyle.Transient,
                Component.For <ITagService>().ImplementedBy <TagService>().LifeStyle.Transient

                //AllTypes.FromThisAssembly().BasedOn<IHttpController>().LifestyleTransient()
                ).AddFacility <LoggingFacility>(f => f.UseLog4Net());
            //扩张单元插件(Facilities)可以在不更改原有组件的基础上注入你所需要的功能代码,
            //AddFacility方法来添加扩展单元来注册并管理我们的组件。
            //组件的生命周期基本上都被指定成为Transient类型,即当请求发生时创建,在处理结束后销毁。

            LoggerFactory.SetCurrent(new TraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
        }
Esempio n. 5
0
        static void ConfigureFactories()
        {
            LoggerFactory.SetCurrent(new TraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var typeAdapterFactory = _currentContainer.Resolve <ITypeAdapterFactory>();

            TypeAdapterFactory.SetCurrent(typeAdapterFactory);
        }
Esempio n. 6
0
        private static void RegistraFabricas(IUnityContainer container)
        {
            LoggerFactory.SetCurrent(new TraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var typeAdapterFactory = container.Resolve <ITypeAdapterFactory>();

            TypeAdapterFactory.SetCurrent(typeAdapterFactory);
        }
        public static void InitializeFactories(TestContext context)
        {
            LoggerFactory.SetCurrent(new TraceSourceLogFactory());

            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var dto = new CountryDTO(); // this is only to force  current domain to load de .DTO assembly and all profiles

            var adapterfactory = new AutomapperTypeAdapterFactory();

            TypeAdapterFactory.SetCurrent(adapterfactory);
        }
 static void ConfigureFactories()
 {
     try
     {
         EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
         TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory());
     }
     catch (Exception exception)
     {
         var aramis = exception.Message;
     }
 }
Esempio n. 9
0
        private void InitializeFactories()
        {
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var dto = new BlogDTO(); // this is only to force  current domain to load de .DTO assembly and all profiles

            var adapterfactory = new AutomapperTypeAdapterFactory();

            TypeAdapterFactory.SetCurrent(adapterfactory);

            //Localization
            LocalizationFactory.SetCurrent(new ResourcesManagerFactory());
        }
Esempio n. 10
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure EntityFramework to use an InMemory database.
            //services.AddDbContext<MyBlogContext>(options =>
            //        options.UseMySql(Configuration.GetConnectionString("MyBlogContext")));
            services.AddDbContext <UnitOfWork>(options =>
            {
                options.EnableSensitiveDataLogging();
                options.UseMySql(Configuration.GetConnectionString("MyBlogContext"));
            });


            services.AddControllersWithViews().AddRazorRuntimeCompilation();

            //services.AddControllersWithViews(options =>
            //{
            //    options.Filters.Add(new ValidateModelAttribute()); // an instance
            //    options.Filters.Add(typeof(LoggerAttribute));
            //}).AddRazorRuntimeCompilation();


            ////Custom Exception and validation Filter
            //services.AddScoped<CustomExceptionFilterAttribute>();


            //Repositories
            services.AddScoped <IBlogInfoRepository, BlogInfoRepository>();
            services.AddScoped <IBlogUserRepository, BlogUserRepository>();
            services.AddScoped <IBlogClassRepository, BlogClassRepository>();



            //DomainServices
            services.AddScoped <IBlogDomainService, BlogDomainService>();
            services.AddScoped <IUserDomainService, UserDomainService>();
            services.AddScoped <IClassDomainService, ClassDomainService>();

            //AppServices
            services.AddScoped <IBlogInfoAppService, BlogInfoAppService>();
            services.AddScoped <IBlogUserAppService, BlogUserAppService>();
            services.AddScoped <IBlogClassAppService, BlogClassAppService>();

            services.AddAutoMapper(typeof(CommonProfile));

            //Validator
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            //Localization
            LocalizationFactory.SetCurrent(new ResourcesManagerFactory());
        }
Esempio n. 11
0
        //Can't get IAS.Common.Configuration solved
        protected void Application_Start(object sender, EventArgs e)
        {
            BootStrapper.ConfigureDependencies();

            ApplicationSettingsFactory.InitializeApplicationSettingsFactory
                (ObjectFactory.GetInstance <IApplicationSettings>());

            LoggerFactory.SetCurrent(new Log4NetOICLogFactory());

            EmailServiceFactory.InitializeEmailServiceFactory
                (ObjectFactory.GetInstance <IEmailService>());

            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            LoggerFactory.CreateLog().LogInfo("WebServiceStart Started");
        }
Esempio n. 12
0
        public void Initialize()
        {
            TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory());
            MapperHelper.Initialise();
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var unitOfWork = new UnitOfWork();

            centroCustoRepository = new CentroCustoRepository(unitOfWork);
            usuarioRepository     = new UsuarioRepository(unitOfWork);
            logAcessoRepository   = new LogAcessoRepository(unitOfWork);
            moduloRepository      = new ModuloRepository(unitOfWork);
            perfilRepository      = new PerfilRepository(unitOfWork);
            messageQueue          = new MessageQueue();
            usuarioAppService     = new UsuarioAppService(usuarioRepository, logAcessoRepository, perfilRepository, moduloRepository, messageQueue);
            centroCustoService    = new CentroCustoAppService(centroCustoRepository, usuarioAppService, messageQueue);
        }
Esempio n. 13
0
        public void Initialize()
        {
            AuthenticationServiceFactory.SetCurrent(new FormsAuthenticationFactory());
            TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory());
            MapperHelper.Initialise();

            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var unitOfWork = new UnitOfWork();

            parametrosOrdemCompraRepository = new Infrastructure.Data.Repository.OrdemCompra.ParametrosOrdemCompraRepository(unitOfWork);
            messageQueue = new MessageQueue();
            parametrosOrcamentoRepository = new ParametrosOrcamentoRepository(unitOfWork);
            parametrosContratoRepository  = new ParametrosContratoRepository(unitOfWork);
            parametrosOrcamentoAppService = new ParametrosOrcamentoAppService(parametrosOrcamentoRepository, messageQueue);
            parametrosContratoAppService  = new ParametrosContratoAppService(parametrosContratoRepository, messageQueue);
        }
Esempio n. 14
0
        public static void RegisterDependency()
        {
            // criando nosso container de dependencias e registrando uma dependencia de exemplo.
            _container = new UnityContainer();
            _container.AddNewExtension <Interception>();

            //-> Unit of Work and repositories
            _container.RegisterType(typeof(MainBCUnitOfWork), new PerResolveLifetimeManager());

            _container.RegisterType(typeof(ITypeAdapterFactory), typeof(AutomapperTypeAdapterFactory));
            var typeAdapterFactory = _container.Resolve <ITypeAdapterFactory>();

            TypeAdapterFactory.SetCurrent(typeAdapterFactory);

            #region RegisterType

            // Repositórios
            _container.RegisterType(typeof(IUsuarioRepository), typeof(UsuarioRepository));
            _container.RegisterType(typeof(IConfiguracaoServidorEmailRepository), typeof(ConfiguracaoServidorEmailRepository));
            _container.RegisterType(typeof(ITokenSenhaRepository), typeof(TokenSenhaRepository));
            _container.RegisterType(typeof(IClienteRepository), typeof(ClienteRepository));
            _container.RegisterType(typeof(IEntrevistaRepository), typeof(EntrevistaRepository));
            _container.RegisterType(typeof(IResponsavelRepository), typeof(ResponsavelRepository));
            _container.RegisterType(typeof(ISocioRepository), typeof(SocioRepository));
            _container.RegisterType(typeof(INumeroOficialRepository), typeof(NumeroOficialRepository));
            _container.RegisterType(typeof(IUsoSoloRepository), typeof(UsoSoloRepository));

            // Serviços
            _container.RegisterType(typeof(IUsuarioAppService), typeof(UsuarioAppService)).Configure <Interception>().SetInterceptorFor <IUsuarioAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(IConfiguracaoAppService), typeof(ConfiguracaoAppService)).Configure <Interception>().SetInterceptorFor <IConfiguracaoAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(IEmailAppService), typeof(EmailAppService)).Configure <Interception>().SetInterceptorFor <IEmailAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(IClienteAppService), typeof(ClienteAppService)).Configure <Interception>().SetInterceptorFor <IClienteAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(IEntrevistaAppService), typeof(EntrevistaAppService)).Configure <Interception>().SetInterceptorFor <INumeroOficialAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(IResponsavelAppService), typeof(ResponsavelAppService)).Configure <Interception>().SetInterceptorFor <IResponsavelAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(ISocioAppService), typeof(SocioAppService)).Configure <Interception>().SetInterceptorFor <ISocioAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(INumeroOficialAppService), typeof(NumeroOficialAppService)).Configure <Interception>().SetInterceptorFor <INumeroOficialAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(IUsoSoloAppService), typeof(UsoSoloAppService)).Configure <Interception>().SetInterceptorFor <IUsoSoloAppService>(new InterfaceInterceptor());
            #endregion

            //modificando o DependencyResolver para a nossa customização passando o container.
            DependencyResolver.SetResolver(new UnityDependencyResolver(_container));

            LoggerFactory.SetCurrent(new EmailTraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
        }
Esempio n. 15
0
        void Application_Start(object sender, EventArgs e)
        {
            // OfflineAll();

            BootStrapper.ConfigureDependencies();
            ApplicationSettingsFactory.InitializeApplicationSettingsFactory
                (ObjectFactory.GetInstance <IApplicationSettings>());
            LoggerFactory.SetCurrent(new Log4NetServiceLogFactory());
            EmailServiceFactory.InitializeEmailServiceFactory
                (ObjectFactory.GetInstance <IEmailService>());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
            LoggerFactory.CreateLog().LogInfo("Web Soria Started" + DateTime.Now.Minute);

            Thread thread = new Thread(new ThreadStart(ThreadFunc));

            thread.IsBackground = true;
            thread.Name         = "ThreadFunc";
            thread.Start();
        }
Esempio n. 16
0
        static Container()
        {
            _currentContainer = new WindsorContainer();

            _currentContainer.Register(
                Component.For <ILoggerFactory>().ImplementedBy <Log4NetLogFactory>().Named("log4net").IsDefault(),
                Component.For <ILoggerFactory>().ImplementedBy <TraceSourceLogFactory>().Named("tracesourcelog"),
                Component.For <ITypeAdapterFactory>().ImplementedBy <EmitMapperTypeAdapterFactory>().Named("EmitMapper"),
                Component.For <ITypeAdapterFactory>().ImplementedBy <AutoMapperTypeAdapterFactory>().Named("AutoMapper").IsDefault());

            var loggerFactory = _currentContainer.Resolve <ILoggerFactory>();

            LoggerFactory.SetCurrent(loggerFactory);

            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            var typeAdapterFactory = _currentContainer.Resolve <ITypeAdapterFactory>();

            TypeAdapterFactory.SetCurrent(typeAdapterFactory);
        }
Esempio n. 17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <MainBCUnitOfWork>();
            //Custom Exception and validation Filter
            services.AddScoped <CustomExceptionFilterAttribute>();

            //Repositories

            services.AddScoped <IBankAccountRepository, BankAccountRepository>();
            services.AddScoped <ICountryRepository, CountryRepository>();
            services.AddScoped <ICustomerRepository, CustomerRepository>();
            services.AddScoped <IOrderRepository, OrderRepository>();
            services.AddScoped <IProductRepository, ProductRepository>();

            // Domain Services
            services.AddScoped <IBankTransferService, BankTransferService>();

            services.AddScoped <ISalesAppService, SalesAppService>();
            services.AddScoped <ICustomerAppService, CustomerAppService>();
            services.AddScoped <IBankAppService, BankAppService>();

            //Adapters
            services.AddScoped <ITypeAdapterFactory, AutomapperTypeAdapterFactory>();
            TypeAdapterFactory.SetCurrent(services.BuildServiceProvider().GetService <ITypeAdapterFactory>());

            //Validator
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            //Localization
            LocalizationFactory.SetCurrent(new ResourcesManagerFactory());


            // Add framework services.
            services.AddMvc(options =>
            {
                options.Filters.Add(new ValidateModelAttribute()); // an instance
                options.Filters.Add(typeof(LoggerAttribute));
            });
        }
Esempio n. 18
0
        private static void SetAutofacConfig()
        {
            var builder = new ContainerBuilder();

            var config = GlobalConfiguration.Configuration;

            // Register Controllers
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            //Register Session
            builder.RegisterType <SessionHandler>().As <ISessionHandler>().InstancePerRequest();

            //Register MainBcUnitOfWork
            builder.RegisterType <MainBcUnitOfWork>().InstancePerLifetimeScope();

            //Register Automapper
            builder.RegisterType <AutomapperTypeAdapterFactory>().As <ITypeAdapterFactory>().InstancePerLifetimeScope();

            //Register Repository Factory
            builder.RegisterType <RepositoryFactory>().As <IRepositoryFactory>().InstancePerRequest();

            //Register AppService Factory
            builder.RegisterType <AppServiceFactory>().As <IAppServiceFactory>().InstancePerRequest();

            //Build
            builder.RegisterFilterProvider();
            IContainer container = builder.Build();

            var typeAdapterFactory = container.Resolve <ITypeAdapterFactory>();

            TypeAdapterFactory.SetCurrent(typeAdapterFactory);

            //Dependency Resolver
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            //Validator
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
        }
Esempio n. 19
0
        public static void RegisterDependency()
        {
            // criando nosso container de dependencias e registrando uma dependencia de exemplo.
            _container = new UnityContainer();
            _container.AddNewExtension <Interception>();

            //-> Unit of Work and repositories
            _container.RegisterType(typeof(MainBCUnitOfWork), new PerResolveLifetimeManager());

            _container.RegisterType(typeof(ITypeAdapterFactory), typeof(AutomapperTypeAdapterFactory));
            var typeAdapterFactory = _container.Resolve <ITypeAdapterFactory>();

            TypeAdapterFactory.SetCurrent(typeAdapterFactory);

            #region RegisterType

            // Repositórios
            _container.RegisterType(typeof(IUsuarioRepository), typeof(UsuarioRepository));
            _container.RegisterType(typeof(IPessoaRepository), typeof(PessoaRepository));
            _container.RegisterType(typeof(IMarcaProdutoRepository), typeof(MarcaProdutoRepository));
            _container.RegisterType(typeof(ICategoriaProdutoRepository), typeof(CategoriaProdutoRepository));
            _container.RegisterType(typeof(IProdutoRepository), typeof(ProdutoRepository));

            // Serviços
            _container.RegisterType(typeof(IUsuarioAppService), typeof(UsuarioAppService)); //.Configure<Interception>().SetInterceptorFor<IUsuarioAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(IPessoaAppService), typeof(PessoaAppService));   //.Configure<Interception>().SetInterceptorFor<IPessoaAppService>(new InterfaceInterceptor());
            _container.RegisterType(typeof(IMarcaProdutoAppService), typeof(MarcaProdutoAppService));
            _container.RegisterType(typeof(ICategoriaProdutoAppService), typeof(CategoriaProdutoAppService));
            _container.RegisterType(typeof(IProdutoAppService), typeof(ProdutoAppService));

            #endregion

            //modificando o DependencyResolver para a nossa customização passando o container.
            DependencyResolver.SetResolver(new UnityDependencyResolver(_container));

            LoggerFactory.SetCurrent(new EmailTraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
        }
Esempio n. 20
0
        public static IUnityContainer AddContainerDataSolicitud(this IUnityContainer container)
        {
            container.RegisterType(typeof(DbContext), typeof(SolicitudDbContext), new TransientLifetimeManager());


            container.RegisterType(typeof(ITypeAdapterFactory));

            container.RegisterType <IServicebApi, ServicebApi>();

            ////-> Adapters
            container.RegisterType <ITypeAdapterFactory, AutomapperTypeAdapterFactory>(new ContainerControlledLifetimeManager());

            //LoggerFactory.SetCurrent(new TraceSourceLogFactory());
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
            ////  AutomapperTypeAdapter

            ////container.RegisterType(typeof(ITypeAdapterFactory), new PerResolveLifetimeManager());
            var typeAdapterFactory = container.Resolve <ITypeAdapterFactory>();

            TypeAdapterFactory.SetCurrent(typeAdapterFactory);


            return(container);
        }
Esempio n. 21
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure EntityFramework to use an InMemory database.
            services.AddDbContext <BloggingContext>();

            // Add framework services.
            services.AddMvc(options =>
            {
                options.Filters.Add(new ValidateModelAttribute()); // an instance
                options.Filters.Add(typeof(LoggerAttribute));
            })
            .AddFluentValidation(fv => { });

            // can then manually register validators
            services.AddTransient <IValidator <BlogDTO>, BlogDTOValidator>();
            services.AddTransient <IValidator <PostDTO>, PostDTOValidator>();

            //Custom Exception and validation Filter
            services.AddScoped <CustomExceptionFilterAttribute>();

            //Repositories
            services.AddScoped <IImageRepository, ImageRepository>();
            services.AddScoped <IPostRepository, PostRepository>();
            services.AddScoped <IBlogRepository, BlogRepository>();

            //Services
            services.AddScoped <IPostsService, PostsService>();
            services.AddScoped <IBlogsService, BlogsService>();

            //Adapters
            services.AddScoped <ITypeAdapterFactory, AutomapperTypeAdapterFactory>();
            TypeAdapterFactory.SetCurrent(services.BuildServiceProvider().GetService <ITypeAdapterFactory>());

            //Validator
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            //Localization
            LocalizationFactory.SetCurrent(new ResourcesManagerFactory());

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Version        = "v1",
                    Title          = "DDD N-Layered Architecture",
                    Description    = "DDD N-Layered Architecture with .Net Core 2 (NLayerAppV3)",
                    TermsOfService = "None",
                    Contact        = new Swashbuckle.AspNetCore.Swagger.Contact {
                        Name = "César Castro", Email = "*****@*****.**", Url = "https://www.linkedin.com/in/c%C3%A9sar-castro-91b56211/"
                    },
                    License = new Swashbuckle.AspNetCore.Swagger.License {
                        Name = "Use under my own License", Url = "https://www.microsoft.com/net/learn/architecture"
                    }
                });

                //Set the comments path for the swagger json and ui.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "NLayerApp.DistributedServices.BlogBoundedContext.xml");
                c.IncludeXmlComments(xmlPath);
            });
        }
Esempio n. 22
0
 public ValidatorsTests()
 {
     // Initialize default log factory
     EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
 }
Esempio n. 23
0
 public static void InitializeEntityValidator()
 {
     EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
 }
Esempio n. 24
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // To add enviroment variable
            services.Configure <AppSettings>(Configuration.GetSection("ApplicationSettings"));

            //allow cors
            services.AddCors(o => o.AddPolicy("AllowAnyOriginPolicy", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));

            //Inject Application User Identity
            services.AddHttpContextAccessor();
            services.AddScoped <IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped <IApplicationUser, ApplicationUser>();

            // Controllers
            services.AddControllers();

            // Configure EntityFramework to use an InMemory database.
            services.AddDbContext <MainDbContext>(options =>
                                                  options.UseSqlServer(
                                                      Configuration["DatabaseSettings:SqlServerConnection"],
                                                      x => x.MigrationsAssembly("VolvoCash.DistributedServices.MainContext")
                                                      ));

            // Add framework services.
            services.AddMvc(options =>
            {
                options.Filters.Add(new ValidateModelAttribute()); // an instance
                options.Filters.Add(typeof(LoggerAttribute));
                options.EnableEndpointRouting = false;
            })
            .AddFluentValidation(fv => { });

            services.AddControllers().AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                options.SerializerSettings.NullValueHandling     = NullValueHandling.Ignore;
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });

            // Custom Exception and validation Filter
            services.AddScoped <CustomExceptionFilterAttribute>();

            // Application Services
            services.AddScoped <IAuthenticationAppService, AuthenticationAppService>();
            services.AddScoped <ICardAppService, CardAppService>();
            services.AddScoped <IContactAppService, ContactAppService>();
            services.AddScoped <ITransferAppService, TransferAppService>();
            services.AddScoped <IChargeAppService, ChargeAppService>();
            services.AddScoped <IClientAppService, ClientAppService>();
            services.AddScoped <ILoadAppService, LoadAppService>();

            // Domain Services
            services.AddScoped <ICardTransferService, CardTransferService>();
            services.AddScoped <ICardRechargeService, CardRechargeService>();
            services.AddScoped <ICardChargeService, CardChargeService>();

            // Repositories
            services.AddScoped <ISMSCodeRepository, SMSCodeRepository>();
            services.AddScoped <IContactRepository, ContactRepository>();
            services.AddScoped <ICardRepository, CardRepository>();
            services.AddScoped <ICardTypeRepository, CardTypeRepository>();
            services.AddScoped <IClientRepository, ClientRepository>();
            services.AddScoped <ITransferRepository, TransferRepository>();
            services.AddScoped <IChargeRepository, ChargeRepository>();
            services.AddScoped <ICashierRepository, CashierRepository>();
            services.AddScoped <IAdminRepository, AdminRepository>();

            //Common Services
            services.AddScoped <IAmazonBucketService, AmazonBucketService>();
            services.AddScoped <IUrlManager, UrlManager>();

            // Adapters
            services.AddScoped <ITypeAdapterFactory, AutomapperTypeAdapterFactory>();
            TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory());

            // Configure JWTToken Authentication
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["JWT:Issuer"],
                    ValidAudience    = Configuration["JWT:Audience"],
                    IssuerSigningKey = new SymmetricSecurityKey(
                        Encoding.UTF8.GetBytes(Configuration["JWT:SecretKey"])
                        )
                };
            });

            // Validator
            EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());

            // Localization
            LocalizationFactory.SetCurrent(new ResourcesManagerFactory());
        }
Esempio n. 25
0
 /// <summary>
 /// Factories configuration
 /// </summary>
 private static void ConfigureFactories()
 {
     //LoggerFactory.SetCurrent(new TraceSourceLogFactory());
     EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
     //TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory());
 }
Esempio n. 26
0
 public static void ClassInitialze(TestContext context)
 {
     // Initialize default log factory
     EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
 }