public void Setup() { var list = new List <Registry>(); list.Add(new ServiceRegistry()); ConfigureDependencies.InitContainer(list); }
public void Setup() { var list = new List <Registry>(); list.Add(new ServiceRegistry()); ConfigureDependencies.InitContainer(list); var container = ConfigureDependencies.GetContainer(); DependencyResolver.SetResolver(new StructureMapDependencyScope(container)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { IdentityModelEventSource.ShowPII = true; services.AddDbContext <ApiContext>(opt => opt.UseSqlite("Data Source=StockManagement.db;")); // Validation rules services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddFluentValidation(); var mappingConfig = new MapperConfiguration(mc => { { mc.CreateMissingTypeMaps = false; mc.AddProfile(new MappingProfiles()); } }); // Set Adapter pattern var mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); ConfigureJwt(services); var ded = new ConfigureDependencies(); ded.ConfigureRepositories(services); ded.ConfigureServices(services); services.AddSwaggerGen(s => { s.SwaggerDoc("v1", new OpenApiInfo { Title = "StockManagement API", Description = "StockManagement API" }); }); var corsBuilder = new CorsPolicyBuilder(); corsBuilder.AllowAnyHeader(); corsBuilder.AllowAnyMethod(); corsBuilder.SetIsOriginAllowed(host => true); corsBuilder.AllowCredentials(); services.AddCors(options => { options.AddPolicy("SiteCorsPolicy", corsBuilder.Build()); }); }
public static void Initialise() { List <Registry> rlist = new List <Registry>(); rlist.Add(new ServiceRegistry()); IContainer container = ConfigureDependencies.InitContainer(rlist); //Register for MVC DependencyResolver.SetResolver(new StructureMapDependencyScope(container)); //Register for Web API //GlobalConfiguration.Configuration.DependencyResolver = new StructureMapResolver(container); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers() .ConfigureApiBehaviorOptions(options => { options.InvalidModelStateResponseFactory = actionContext => { var modelState = actionContext.ModelState.Values; return(new BadRequestObjectResult(new ErrorModel(modelState))); }; }); services.AddSwaggerGen(swagger => { swagger.SwaggerDoc( "v1", new OpenApiInfo { Title = "Contacts Demo", Version = "v1", Description = "Contact List", Contact = new OpenApiContact { Name = "Cezar K de Carvalho", Email = "*****@*****.**" } }); string applicationPath = PlatformServices.Default.Application.ApplicationBasePath; string applicationName = PlatformServices.Default.Application.ApplicationName; string xmlPathDoc = Path.Combine(applicationPath, $"{applicationName}.xml"); swagger.IncludeXmlComments(xmlPathDoc); }); ConfigureDependencies.BuildDependencies(services); }
public async Task StartApplication() { MessageBrokerContext.SetEnvironment(Configuration.Environment); var azureConfiguration = new AzureServiceBusConfiguration { ConnectionString = File.ReadAllText($"{AppContext.BaseDirectory}\\ConnectionString.txt") }; var logInstance = new LoggerConfiguration() .MinimumLevel.Verbose() .Enrich.FromLogContext() .Enrich.WithProperty("Environment", "Testing") .WriteTo.Seq("http://localhost:5341") .CreateLogger(); _resolver = ConfigureDependencies.Initialise() .AddAzureServiceBusTransportProvider(azureConfiguration) .AddCoreDependencies() .ScanForHandlers(Assembly.GetExecutingAssembly()) .Build(); var configurationBuilder = _resolver.GetInstance <BusConfigurationBuilder>(); await configurationBuilder .SubscribeToQueue <TestQueue>() .SubscribeToEvent <TestEventV1>(Configuration.Subscription1) .SubscribeToEvent <MultipleSubscribersEventV1>(Configuration.Subscription1) .SubscribeToEvent <MultipleSubscribersEventV1>(Configuration.Subscription2) .PublishEvent <TestEventV1>() .PublishEvent <MultipleSubscribersEventV1>() .UseLogger(logInstance) .BuildAsync(); _monitor = _resolver.GetInstance <IMonitor>(); _monitor.Start(); Bus = _resolver.GetInstance <IBus>(); }
/// <summary> /// 根据类型获取类型的示例,StructureMap中没有注册过的类型同样可以可以使用ObjectFactory创建 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="pluginType">需要实例化的对象类型</param> /// <returns></returns> public static T GetInstance <T>(Type pluginType) { return((T)ConfigureDependencies.GetContainer().GetInstance(pluginType)); }
/// <summary> /// 获取对象的实例,StructureMap中没有注册过的类型同样可以可以使用ObjectFactory创建 /// </summary> /// <typeparam name="T">类型</typeparam> /// <returns></returns> public static T GetInstance <T>() { //var a= ObjectFactory.Container.GetInstance<T>(); return(ConfigureDependencies.GetContainer().GetInstance <T>()); }
public void Clear() { ConfigureDependencies.DisposeContainer(); }
public ItIs() { _bootstrapper = new Bootstrapper(); _configureDependencies = new ConfigureDependencies(); _conventions = new List<IRegistrationConvention>(); }