structuremap

StructureMap controller factory and null controller instance in MVC

大城市里の小女人 提交于 2019-12-03 17:26:31
问题 I'm still trying to figure things out with StructureMap and one of the issues i'm running into is my Controller Factory class blowing up when a null controller type is passed to it. This only happens when the application builds for the first time, after which every subsequent build works fine. Even when i shutdown Visual Studio and reopen the project (I'm not running this in IIS). It's almost like there is some sort of caching going on. This is what the controller class looks like: public

Issues Configuring StructureMap.MVC5 to work with Identity

空扰寡人 提交于 2019-12-03 17:06:09
I am currently trying to reconfigure StructureMap in our application after upgrading from an old version (2.6) that was never correctly implemented in the first place. I am new to using DI Containers to begin with, and am finding documentation for newer StructureMap versions hard to find. I uninstalled the old 2.6 version of StructureMap and installed StructureMap.MVC5 (since I am using MVC5). What I am having issues with is the AccountController. I have StructureMap set up to use the parameterless constructor, but when my application tries to create the UserManager, I get an

How to configure dependency injection with ASP.NET MVC 3 RTM

…衆ロ難τιáo~ 提交于 2019-12-03 16:59:24
I am upgrading a web app from ASP.NET 3 Preview 1 to the RTM and I am confused by the updated approach to dependency injection. I am using StructureMap for this but that's not really relevant to my question. Previously all I needed to do was as follows: x.For<IControllerFactory>().Use<DefaultControllerFactory>(); x.For<IServiceLocator>().Use(MvcServiceLocator.Current); Now it seems like I need to provide implementations of IControllerActivator, IViewPageActivator and ModelMetadataProvider because otherwise I get an error from StructureMap because MVC tries to locate them using the dependency

SQL Azure: More Intermittent Timeouts

☆樱花仙子☆ 提交于 2019-12-03 16:28:16
We have a set of 5 online auction systems running on Windows Azure & SQL Azure. Each system consists of a single web worker and one or more web roles. Each system is using ASP.NET MVC 3 and Entity Framework, Repository Pattern and StructureMap. The worker role is responsible for housekeeping and runs two groups of processes. One group is run every ten seconds, the other every second. Each process will likely run a database query or stored procedure. These are scheduled with Quartz.net The web role serves the public interface and back office. Among other basic crud functionality, both of these

Simple but good example on how to use Dapper with Structuremap and dependency injection

吃可爱长大的小学妹 提交于 2019-12-03 15:00:35
I am trying to understand how to use Dependency Injection with Dapper (IDbConnection) and still being able to use built in dispose. I have found a couple of articles on the web but non that I think is easy to understand. What I am trying to figure out is how to make this simple class be testable: public class UserProfileRepository : IUserProfileRepository { private readonly IConfigRepository _configRepository; public UserProfileRepository(IConfigRepository configRepository) { _configRepository = configRepository; } public UserProfile GetUserProfile(string userId) { const string query = @

How to release HybridHttpOrThreadLocalScoped objects in StructureMap?

北城余情 提交于 2019-12-03 13:42:10
When performing background tasks in a Windows Service I used HybridHttpOrThreadLocalScoped for storing intances of NHibernate ISessions. Since within a Windows Server there isn't a HTTPContext, I'm wondering if only calling the ReleaseAndDisposeAllHttpScopedObjects() is enough to release the ISession instance for that thread? I found out how to answer this question. The ReleaseAndDisposeAllHttpScopedObjects() method exposed by the ObjectFactory is really concerned with the HttpContext and therefore web applications. The HybridLifeCycle class from the Structuremap.Pipeline namespace allows to

How to dispose resources with dependency injection

倾然丶 夕夏残阳落幕 提交于 2019-12-03 10:45:46
问题 I'm using StructureMap to resolve references to my repository class. My repository interface implements IDisposable, e.g. public interface IMyRepository : IDisposable { SomeClass GetById(int id); } An implementation of the interface using Entity Framework: public MyRepository : IMyRepository { private MyDbContext _dbContext; public MyDbContext() { _dbContext = new MyDbContext(); } public SomeClass GetById(int id) { var query = from x in _dbContext where x.Id = id select x; return x

StructureMap and the decorator pattern

不羁的心 提交于 2019-12-03 10:41:01
I'm using StructureMap, v. 2.5.3 and am having trouble with chaining together implementations on an interface to implement the Decorator pattern. I'm used to Windsor, where it is possible to name variations on interface implementations and send the named impl. into another (default) impl. This is the default, non decorated version, which works fine: ObjectFactory.Initialize(registry => { registry.ForRequestedType<ICommentService() .TheDefault.Is.OfConcreteType<CommentService>(); ... } This is the ctor on the decorator, that I want to call: public CommentAuditService( ICommentService

StructureMap, NHibernate and multiple databases

你说的曾经没有我的故事 提交于 2019-12-03 09:59:13
问题 I'm working on an Asp.Net MVC 3 application using Fluent NHibernate. I'm just attempting to add an IoC container using StructureMap. I have implemented a custom controller factory which uses StructureMap to create the controller and inject dependencies. Each controller constructor takes one or more services, which in turn take a DAO as constructor argument. Each DAO constructor takes an ISessionFactory. For my StructureMap NHibernate registry I have the following: internal class

asp.net MVC 4 with StructureMap

假如想象 提交于 2019-12-03 09:38:18
问题 I am converting an ASP.NET MVC3 project to MVC4. I was trying to find the best approach to work with StructureMap and MVC4. I've found a couple of solution which might work, but haven't tried them yet. The first solution is very simple and lightweight. The second one (Structuremap.MVC4) depends on WebActivator for the startup. What is the better and simplest approach? Do I still need to bootstrap everything and set the DependencyResolver with the WebActivator? Thanks for your help. 回答1: I did