structuremap

Controlling NHibernate ITransaction with StructureMap?

I'm using StructureMap as my IoC container and NHibernate as my ORM. I found an example online that shows how to have StructureMap build the ISessionFactory and the ISession so the Factory is a singleton and the Session is based on the HttpContext. This works great, but then I started using NH Profiler which told me I should always be ex...

Different ways to inject dependencies in ASP.NET MVC Controllers?

In most samples I have seen on the web, DI in MVC Controllers is done like this public ProductController(IProductRepository Rep) { this._rep = Rep; } A custom ControllerFactory is used and it utilizes the DI framework of choice and the repository is injected. Why is the above considered better than public ProuctController() { ...

NHibernate unable to pick up new data from the database

Hi all, I am using NHibernate to as the Data Access layer for my ASP.NET MVC application. I am also using Structure Map as an IoC container. I have configured Structre map to create a session factory as a singleton and create sessions on a per request basis (InstanceScope.Hybrid). I am able to do basic CRUD operations just fine. Now, I ...

Structure Map - I dont want to use the greediest constructor!

I am trying to configure the NCommon NHRepository in my project with Structure Map. How do I stop it from choosing the greediest constructor? public class NHRepository<TEntity> : RepositoryBase<TEntity> { public NHRepository () {} public NHRepository(ISession session) { _privateSession = session; } ......

Is there a way to detect and debug circular references when using StructureMap?

Lately I've been using a larger number of smaller objects, because they are simpler and easier to reuse. Most of the time there isn't any problem injecting these objects into one another using StructureMap (great tool, btw). But occasionally, I f*** up, and I get myself a nice circular reference in the guise of a stack overflow excepti...

Structuremap configuration: One object, multiple interfaces

I have this object "mySessionObject" of type "SessionObject". It implements the interfaces IMessageHandler<MessageA> and IMessageHandler<MessageB>. I should only have one of these objects, and it should live thru the entire HttpSession. How do I register it with structuremap so that I at any time in the lifetime of the HttpSession can g...

Define default constructor with StructureMap without providing arguements or using DefaultConstructor attribute

I've been using StructureMap for sometime now but I'm far from an expert. My problem is simple, I'm trying to configure SM via code (Registry) to use a particular constructor when creating an instance of a repository object. Here are my 2 constructors (note neither is the greediest). public BusinessUnitRepository( IDatabase database )...

NHibernate and Structure Map

So I really like working with NHibernate but always used Spring.Net with it. I recently came across StructureMap by Jeremy Miller and really like it better than Spring.Net. On his StructureMap site he promises an example on how to use NHibernate and StructureMap together. Unfortunately he has not had time to do it (or I can't find i...

MVVM and StructureMap usage

I have quite a large number of parent-detail ViewModels in my MVVM application. Something like this: SchoolsViewModel +- SchoolViewModel +- LessonViewModel +- PupilsViewModel +- PupilViewModel +- TeacherViewModel +- PupilsViewModel +- PupilViewModel +- LessonsViewMo...

How to register generic interfaces in StructureMap...

How do I register all the instances of a generic interface in Structured Map? I know how to do this for a none generic interface: internal class MVCDemoRegistry : Registry { public MVCDemoRegistry() { Scan(x => { x.Assembly("MVCDemo"); x.Assembly("MVCDemo.Infra...

StructureMap WithCtorArg - missing reference?

I'm trying to get started with Structure Map. I'm using version 2.5.3. I've built a simple boot strapper, but I can't get it to compile. I get the error: 'StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression' does not contain a definition for 'WithCtorArg' and no extension method 'WithCtorArg' accepting a first argum...

Constructor dependency injection with NHibernate 2.1 and StructureMap

I've read somewhere that NHibernate 2.1 supports constructor dependency injection for it's entites. How do I go about configuring StructureMap and NHibnerate 2.1 to get this up and running ? ...

How do I do this in Unity?

Jimmy Bogart has an article on using Automapper with an IoC container. He has an example using StructureMap but I am using Unity and I'm not sure how to use an InjectionConstructor properly. Below is the code from the Article and below that is my poor attempt. Can anyone tell me how to do this properly? public class ConfigurationRegis...

StructureMap Exception Code: 202 No Default Instance defined...

When I register the following in SM and then attempt to create an instance I get the exception - 'StructureMap Exception Code: 202 No Default Instance defined for PluginFamily...' Scan(x => { x.Assembly("MVCDemo"); x.Assembly("MVCDemo.Infrastructure"); x.Assembly("MVCDemo.Services"); ...

Dump the container configuration in StructureMap

I have a ever growing project using StructureMap as the IOC container. I am trying to reduce the amount of code in the StructureMap registries by using the auto-registration with Scan(). As I make changes is there an easy way to dump the current container to the console so i can see if the changes have done what I expected? ...

StructureMap and passing null parameter to instance

I am creating an instance with StructureMap in code, and the constructor takes in a string. In the configuration I use a placeholder for the parameter. I am trying to create the object with the parameter value of null. When I get the object back from the ObjectFactory the value of the parameter is equal to the placeholder, not null. ...

Simple Factory using StructureMap

Posted this on the structuremap group as well. We just started using structuremap last week, and are really digging it. I'm sure I'm missing something simple. I am trying to mimic the following code, using SM within my factory. I'm ok with having the container dependency in the factory class. The consensus in this thread seemed ...

Structuremap Scope/Lifecycle Guidance?

Is there any reason to switch from the default scope (transient?) to something else, outside of needing to control the scope for functional reasons (e.g. Singleton)? If I stick with the default scope, every default instance of every plugin type will effectively get instantiated on each request (assuming a web app), is that correct? Can...

Get instance conditionally in StructureMap

Hi, I have an interface IFileSystemStructureEvaluator with two concrete implementations: NtfsFileSystemStructureEvaluator and FtpFileSystemStructureEvaluator. I want to be able to request the appropriate IFileSystemStructureEvaluator depending on whether the Uri that is passed to the constructor is a file uri of an FTP uri. How can I ...

Reset ObjectFactory in StructureMap

I'm writing some unit tests that rely on StructureMap so I want to completely reset the ObjectFactory in my [SetUp] method. This is what my [SetUp] method looks like right now: [SetUp] public void SetUp() { ObjectFactory.Initialize(initializationExpression => {}); } This appears to reset the configuration because I can execute th...