structuremap

Dispose of Injected HttpClient

北城以北 提交于 2019-12-21 02:44:11
问题 Our MVC application calls a WebAPI action using HttpClient. I decided to inject the HttpClient using StructureMap and override dispose in the controller public HomeController(HttpClient httpClient) { _httpClient = httpClient; } protected override void Dispose(bool disposing) { if (disposing && _httpClient != null) { _httpClient.Dispose(); } base.Dispose(disposing); } The StructureMap ObjectInitialize basically looks like this.. x.For<HttpClient>().Use(() => new HttpClient() { BaseAddress =

Inject AutoMapper

百般思念 提交于 2019-12-21 01:17:47
问题 I have been working on injecting AutoMapper into controllers. I like the implementation of Code Camp Server. It creates a wrapper around AutoMapper's IMappingEngine. The dependency injection is done using StructureMap. But I need to use Castle Windsor for my project. So, how do we implement the following dependency injection and set-up using Windsor? I am not looking for line-by-line equivalent implementation in Castle Windsor. If you want to do that, please feel free. Instead, what is

Entity Framework : Change connection string at runtime

半腔热情 提交于 2019-12-20 11:37:14
问题 Assuming there is an ASP.NET MVC application that uses Entity Framework 6 with code-first approach and StructureMap as IoC. Also It uses Unit Of Work pattern. Here are the codes : Domain Class public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } } IUnitOfWork and DbContext : public interface IUnitOfWork { IDbSet<TEntity> Set<TEntity>() where TEntity : class; int SaveChanges(); } public class Sample07Context : DbContext,

using (Fluent) NHibernate with StructureMap (or any IoCC)

半世苍凉 提交于 2019-12-20 10:54:28
问题 On my quest to learn NHibernate I have reached the next hurdle; how should I go about integrating it with StructureMap? Although code examples are very welcome, I'm more interested in the general procedure. What I was planning on doing was... Use Fluent NHibernate to create my class mappings for use in NHibs Configuration Implement ISession and ISessionFactory Bootstrap an instance of my ISessionFactory into StructureMap as a singleton Register ISession with StructureMap, with per-HttpRequest

NLog GetCurrentClassLogger() NullReferenceException using StructureMap (Full Trust)

自古美人都是妖i 提交于 2019-12-20 10:37:34
问题 It seems like NLog can't use reflection for GetCurrentClassLogger() , even though my MVC 3 app is deployed in a Full Trust environment on IIS7. I'm using StructureMap 2.6.1 and the problem seems to appear sporadically between deploys. I can't figure out why, though I don't think StructureMap is causing it. Bootstrapper class: public static class Bootstrapper { public static void ConfigureStructureMap() { ObjectFactory.Initialize(Init); } private static void Init(IInitializationExpression x) {

StructureMap Tutorial [closed]

风格不统一 提交于 2019-12-20 08:51:13
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I am look for some Structure map Tutorials. Does anyone know of any? EDIT: All answers are appreciated but I was looking for something

StructureMap: Choose concrete type of nested dependency

試著忘記壹切 提交于 2019-12-19 19:51:31
问题 Calculators: public interface ICalculator { int Calculate(int a, int b); } public class Calculator : ICalculator { private readonly ICalculatorStrategy _calculatorStrategy; public Calculator(ICalculatorStrategy calculatorStrategy) { _calculatorStrategy = calculatorStrategy; } public int Calculate(int a, int b) { return _calculatorStrategy.Calculate(a, b); } } Calculator stragies: public interface ICalculatorStrategy { int Calculate(int a, int b); } public class AdditionCalculator :

Structuremap Disposing of DataContext object

回眸只為那壹抹淺笑 提交于 2019-12-19 07:10:11
问题 I wanted to be sure if structuremap will dispose my DataContext after per request ends. Here is my setup ForRequestedType<MyDataContext>().TheDefault.Is.OfConcreteType<MyDataContext>(); SelectConstructor<MyDataContext>(() => new MyDataContext()); Will structuremap auto dispose my datacontext or do i need to call Dispose manually?? 回答1: No it will not Dispose it automatically, unless you use nested containers and Dispose the container holding the context instance. It's up to the creator of the

Structuremap Disposing of DataContext object

对着背影说爱祢 提交于 2019-12-19 07:10:04
问题 I wanted to be sure if structuremap will dispose my DataContext after per request ends. Here is my setup ForRequestedType<MyDataContext>().TheDefault.Is.OfConcreteType<MyDataContext>(); SelectConstructor<MyDataContext>(() => new MyDataContext()); Will structuremap auto dispose my datacontext or do i need to call Dispose manually?? 回答1: No it will not Dispose it automatically, unless you use nested containers and Dispose the container holding the context instance. It's up to the creator of the

Mapper not initialized, When Use ProjectTo()

我们两清 提交于 2019-12-18 19:01:33
问题 I Use Automapper 5.2.0 In My Project. When I Use ProjectTo() In Code Get This Error: Mapper not initialized. Call Initialize with Appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance. Service Code public async Task