static async Task Main(string[] args) { IoCConfiguration.Setup(); int a = 2, b = 0; try { int c = a / b; } catch (Exception exception) { await Logging.SaveAsync(exception, AssemblyHelper.AssemblyName, ConsoleErrorType.DivideByZero); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext <AppDbContext>(options => options.UseInMemoryDatabase("DBConversor")); IoCConfiguration.ConfigureServices(services, Configuration); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "API", Description = "Service Web API", }); }); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc() .AddJsonOptions(opt => { //var resolver = opt.SerializerSettings.ContractResolver; //if (resolver != null) //{ // var res = resolver as DefaultContractResolver; // res.NamingStrategy = null; // <<!-- this removes the camelcasing //} var jsonSettings = opt.SerializerSettings; jsonSettings.Formatting = Formatting.Indented; jsonSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); jsonSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); services.AddSingleton(Configuration); IoCConfiguration.Configure(services); }
private static void BuildApp(IAppBuilder app, string publicDirectoryPath) { var container = IoCConfiguration.CreateIoCContainer(); var httpConfig = new HttpConfiguration { DependencyResolver = container.Resolve <System.Web.Http.Dependencies.IDependencyResolver>() }; WebAppConfiguration.ConfigureFileSystem(app, publicDirectoryPath); WebAppConfiguration.ConfigureAuthentication(app); WebAppConfiguration.ConfigureWebApi(app, httpConfig); WebAppConfiguration.ConfigureFilters(httpConfig, container); app.UseAutofacMiddleware(container); // must be at the end app.UseWebApi(httpConfig); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); IoCConfiguration.Configure(services); services.AddScoped <TodoValidator>(); services.AddSwaggerGen(); var pathToDoc = Configuration["Swagger:Path"]; //localhost:59103/swagger/ui/index.html services.ConfigureSwaggerGen(options => { options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info { Version = "v1", Title = "TodoApp Api", Description = "", TermsOfService = "none" }); options.IncludeXmlComments(pathToDoc); options.DescribeAllEnumsAsStrings(); }); services.AddMvc(); }
public static void Register(HttpConfiguration config) { var jsonFormatter = config.Formatters.OfType <JsonMediaTypeFormatter>().First(); jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); var formatters = GlobalConfiguration.Configuration.Formatters; var settings = jsonFormatter.SerializerSettings; settings.Formatting = Formatting.Indented; settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // Web API configuration and services // Configure Web API to use only bearer token authentication. config.SuppressDefaultHostAuthentication(); config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Web API routes config.MapHttpAttributeRoutes(); // Global exception logger config.Services.Add(typeof(IExceptionLogger), new ElmahExceptionLogger()); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var container = new UnityContainer(); IoCConfiguration.ConfigureAll(ref container); config.DependencyResolver = new UnityResolver(container); }
public SalesManagerTest() { IoCConfiguration.Setup(true); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); IoCConfiguration.Configure(); }
public static void RegisterDynamicDependencies(this IServiceCollection services, IoCConfiguration iocConfiguration) { try { var roles = iocConfiguration.GetRolesByPriority(); foreach (var iocRole in roles) { var assembly = AssemblyConfig.LoadAssembly(iocRole.Dll); var exportedTypes = assembly.ExportedTypes.Where(x => x.FullName .StartsWith(iocRole.Implementation, StringComparison.CurrentCulture)).ToList(); foreach (var exportedType in exportedTypes) { var allowedInterfaces = iocConfiguration.AllowedInterfaceNamespaces?.Count > 0 ? exportedType.GetInterfaces() .Where(i => iocConfiguration.AllowedInterfaceNamespaces.Any(allowedNamespace => i.FullName.ToLower().StartsWith(allowedNamespace.ToLower()))) : exportedType.GetInterfaces(); foreach (var @interface in allowedInterfaces) { switch (iocRole.LifeTime) { case LifeTime.SCOPED: default: services.AddScoped(@interface, exportedType); break; case LifeTime.SINGLETON: services.AddSingleton(@interface, exportedType); break; case LifeTime.TRANSIENT: services.AddTransient(@interface, exportedType); break; } } } } } catch (Exception ex) { throw new DynamicInjectorException(ex.Message); } }
public void ConfigureContainer(ContainerBuilder builder) { IoCConfiguration.AddServiceLocatorTo(builder); }
public void Container_ContainsRepositories_SUCCESS() { IoCConfiguration.ConfigureContainer();; var container = IoCConfiguration.Container; }
public void ConfigureIoC(IServiceCollection services) { IoCConfiguration.Configure(services); }
protected void Application_Start() { AutoMapperConfig.Initialize(); IoCConfiguration.Initialize(GlobalConfiguration.Configuration); GlobalConfiguration.Configure(WebApiConfig.Register); }
public static void Main(string[] args) { IoCConfiguration.ConfigureContainer(); CreateWebHostBuilder(args).Build().Run(); }
public void ConfigureContainer(ContainerBuilder builder) { IoCConfiguration.RegisterRepositories(builder); IoCConfiguration.RegisterServices(builder); }
static InversionOfControl() { IoCConfiguration.ConfigureForTests(); }