Пример #1
0
        protected void Run(Action <IContainer> action)
        {
            var builder = new ContainerBuilder();

            builder.RegisterAppulateModules();
            builder.RegisterModule <PersistenceRegistrationModule>();
            builder.RegisterModule <MessageQueueRegistrationModule>();
            builder.RegisterModule <ProgramSubsystemModule>();

            builder.Register(ctx => AutoMapperConfiguration.Create());
            builder.Register(ctx => ctx.Resolve <MapperConfiguration>().CreateMapper()).As <IMapper>().InstancePerLifetimeScope();

            builder.Register(c => {
                var sharedConfig = new SharedConfig(
                    connectionString: c.Resolve <IDatabaseSettings>().GetDatabaseConnectionString(),
                    storageFolder: c.Resolve <IStorageSettings>().StorageFolder,
                    rabbitMqOptions: new RabbitMqOptions());
                return(new Startup(sharedConfig));
            }).AsSelf().SingleInstance();

            builder.RegisterType <EmptySecurityContext>().As <ISecurityContext>();
            using (IContainer container = builder.Build()) {
                Factory.InitComponentsRegistry(new ComponentsRegistry(container));
                Settings.Initialize(new LocalSettings());
                container.Resolve <Startup>().Init();
                action(container);
            }
        }
 /// <summary>
 /// It adds the AutoMapper dependencies to the container
 /// </summary>
 /// <param name="services"></param>
 public static void AddAutoMapperConfiguration(this IServiceCollection services)
 {
     services.AddScoped <IMapper>(ctx =>
     {
         return(AutoMapperConfiguration.Create().CreateMapper());
     });
 }
Пример #3
0
        public AutoNSubstituteDataAutoMapperAttribute() : base(() =>
        {
            var fixture = new Fixture().Customize(new AutoNSubstituteCustomization());

            fixture.Register <IMapper>(() => AutoMapperConfiguration.Create().CreateMapper());

            return(fixture);
        })
        {
        }
Пример #4
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType <AniraSpDbContext>().AsSelf().InstancePerLifetimeScope();
            builder.RegisterType <PortionUploader>().AsSelf().InstancePerLifetimeScope();
            builder.RegisterType <BulkCopyUploader>().As <IBulkCopyUploader>().InstancePerLifetimeScope();

            builder.RegisterType <DatabaseSettings>().As <IDatabaseSettings>().InstancePerLifetimeScope();

            builder.Register(_ => AutoMapperConfiguration.Create());
            builder.Register(ctx => ctx.Resolve <MapperConfiguration>().CreateMapper()).As <IMapper>()
            .InstancePerLifetimeScope();
            builder.RegisterModule <DataAccessModule>();
        }
Пример #5
0
        /// <summary>
        /// Registers the type mappings with the Unity container.
        /// </summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>
        /// There is no need to register concrete types such as controllers or
        /// API controllers (unless you want to change the defaults), as Unity
        /// allows resolving a concrete type even if it was not previously
        /// registered.
        /// </remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            #region DataContext Registration
            container.RegisterFactory <DbContext>(x =>
            {
                return(new MainDataContext());
            }, new PerRequestLifetimeManager());

            #endregion

            //services
            container.RegisterType <ILoanService, LoanService>();
            container.RegisterType <IClientService, ClientService>();
            container.RegisterType <IInvoiceGeneratorService, InvoiceGeneratorService>();
            container.RegisterType <IInvoiceService, InvoiceService>();

            container.RegisterFactory <IMapper>(x => AutoMapperConfiguration.Create(new MapperProfile()), new PerRequestLifetimeManager());
        }
Пример #6
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            if (env.IsDevelopment())
            {
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();
            }

            builder.AddEnvironmentVariables();

            Configuration = builder.Build();

            _mapperConfiguration = AutoMapperConfiguration.Create();
        }
Пример #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            if (Environment.IsDevelopment())
            {
                services.AddMvc(opts => opts.Filters.Add(new AllowAnonymousFilter()));
            }
            else
            {
                services
                .AddMvc(option => option.EnableEndpointRouting = false)
                .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
            }
            services.AddControllers();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version     = "v1",
                    Title       = "UserManagement API",
                    Description = "User Management API with ASP.NET Core 3.1",
                    Contact     = new OpenApiContact()
                    {
                        Name  = "Dotnet Detail",
                        Email = "*****@*****.**"
                    }
                });
            });

            services.AddDbContext <UserDataContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("Default")))
            .AddTransient <ILoggingWork, LoggingWork>()
            .AddTransient <IReportingWork, ReportingWork>()
            .AddTransient <IUserStory, UserStory>()
            .AddTransient <IOrganisationStory, Organisation>()
            .AddSingleton(typeof(IMapper), AutoMapperConfiguration.Create());
        }
Пример #8
0
 public ToUserTests()
 {
     Mapper = AutoMapperConfiguration.Create();
     Faker  = new Faker();
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        public Automapper_test_mappings()
        {
            var mapperConfig = AutoMapperConfiguration.Create();

            _mapper = mapperConfig.CreateMapper();
        }
Пример #10
0
        public DefaultRegistry()
        {
            //Policies.Interceptors(new MeidatorPipelineDecoration());

            Scan(

                scan =>
            {
                scan.TheCallingAssembly();
                scan.AssemblyContainingType <BusinessRuleException>();
                scan.AssemblyContainingType <ILoggedOnUser>();
                scan.AssemblyContainingType <FindAllUsersForOrganization>();
                scan.WithDefaultConventions();
                scan.With(new ControllerConvention());
                scan.ConnectImplementationsToTypesClosing(typeof(IRequestHandler <,>));
                scan.ConnectImplementationsToTypesClosing(typeof(IAsyncRequestHandler <,>));
                scan.ConnectImplementationsToTypesClosing(typeof(INotificationHandler <>));
                scan.ConnectImplementationsToTypesClosing(typeof(IAsyncNotificationHandler <>));
            });

            For(typeof(IAsyncRequestHandler <,>)).DecorateAllWith(typeof(MediatorPipeline <,>));

            For <MapperConfiguration>().Use(AutoMapperConfiguration.Create());
            For <IMapper>().Use(ctx => ctx.GetInstance <MapperConfiguration>().CreateMapper(ctx.GetInstance));
            For <SingleInstanceFactory>().Use <SingleInstanceFactory>(ctx => t => ctx.GetInstance(t));
            For <MultiInstanceFactory>().Use <MultiInstanceFactory>(ctx => t => ctx.GetAllInstances(t));


            For <IUrlHelper>().Use <UrlDecoratorHelper>();

            For <IUserStore <ApplicationUser> >().Use <UserStore <ApplicationUser> >();



            ForSingletonOf <IDocumentStore>()
            .Use("Build the DocumentStore", () =>
            {
                return(DocumentStore.For(_ =>
                {
                    _.Connection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

                    _.AutoCreateSchemaObjects = AutoCreate.All;


                    _.Events.AddEventType(typeof(ClientRegistered));
                    _.Events.AddEventType(typeof(ClientUpdated));

                    _.Events.AddEventType(typeof(SessionCreated));
                    _.Events.AddEventType(typeof(PlanAddedToSession));
                    _.Events.AddEventType(typeof(SessionUpdated));

                    _.Events.AddEventType(typeof(OrganizationCreated));
                    _.Events.AddEventType(typeof(OrganizationUpdated));

                    _.Events.InlineProjections.Add(new SessionCountProjection());
                    _.Events.InlineProjections.Add(new SuburbProjection());
                    _.Events.InlineProjections.Add(new CityProjection());

                    _.Events.InlineProjections.AggregateStreamsWith <ClientModel>();
                    _.Events.InlineProjections.AggregateStreamsWith <SessionModel>();
                    _.Events.InlineProjections.AggregateStreamsWith <OrganizationModel>();

                    _.Logger(new ConsoleMartenLogger());
                }));
            });

            For <IDocumentSession>()
            .LifecycleIs <ContainerLifecycle>()
            .Use("Lightweight Session", c => c.GetInstance <IDocumentStore>().DirtyTrackedSession());

            For <UserManager <ApplicationUser> >()
            .Use(c => new UserManager <ApplicationUser>(c.GetInstance <IUserStore <ApplicationUser> >()));

            For <IMediator>().Use <Mediator>();
        }