structuremap

Is there a better way to use Castle Windsor's API for Factories?

I am open to other IoC containers, such as NInject and StructureMap if they are much cleaner than this. I hear that StructureMap just introduced "containers" that may simplify this , perhaps? As the title says, is there a better way? This seems like a lot of code, just to register an object that requires a factory to create it. // Th...

StructureMap ObjectFactory.Reset memory leak?

Here's the simple test to reproduce the issue, this is the single class in the whole project and there are no other references: [TestFixture] public class ObjectFactoryTests { [Test] public void ResetMemoryLeak() { for (int i = 1; i < 1000; i++) { ObjectFactory.Reset(); if (i % 10 == 0...

StructureMap IRegistrationConvention to register non default naming convention?

I currently have a bunch of repositories like so IMyRepository IAnotherRepository They all inherit from IRepository (if this helps) How can I get structuremap to use an IRegistryConvention scanner to register my concrete types which are named SqlMyRepository SqlAnotherRepository ...

structuremap bootstrap in class library / dll

What is the best approach to bootstrap a dll using structuremap? I don't really want the consumers of the library to have to configure anything themselves if they don't want to. I am thinking that the .config would likely be the simplest, but then again 2.6.1 is out and I am not familiar with many of its features / changes yet. ...

Structuremap use different concrete type by object type

I have a default concrete type defined in a registry: ForRequestedType<IXRepository>() .TheDefaultIsConcreteType<CacheXRepository>(); The ChaceXRepository has the following constructor: public class CacheXRepository: IXRepository{ public CacheXRepository(IXRepository xRepository,ICache cacheService){ In the constru...

StructureMap and LINQ to SQL Connection String

Hi, I am currently setting the connection string for my linq to sql data context by using a wrapper class so that I can pass a connection string into the generated DataContext constructor: public class DB : GeneratedDataContext { public DB() : base(ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString) {...

Rhino Commons Nhibernate Module w/ Structuremap

Has anyone gotten the NH session management bits from RhinoCommons to work with Structure Map? We already use SM and do not want a dependency on Windsor. ...

StructureMap HowTo: Conditional Construction on Deep Object

I'm having difficulty conditionally creating a dependency. Googling, I have yet to find a good example of using the BuildStack and Conditional Predicates. Here's what I'm doing in the Registry: //snip public SomeRegistry() { this.InstanceOf<IFoo>().Is.Conditional( c => { c.TheDefault.Is.Constru...

Get Instance from StructureMap by Type Name

Is there any way to request an instance from the StructureMap ObjectFactory by the string name of the type? For example, it would be nice to do something like this: var thing = ObjectFactory.GetInstance("Thing"); The use case here is a messaging scenario in which the message is very generic and contains only the name of a task. A ha...

Downloaded StructureMap but seems to be missing the Log4Net.Dll

I am currently following instructions in a book to develop an application. It asks me to download StructureMap and then move the StructureMap.Dll file and the Log4Net.dll into the bin files. The problem is there doesnt seem to be a Log4Net.dll file in the StructureMap files, the only other dll apart from the StructureMap.dll is the Rhino...

How to get all possible generic type in StructureMap?

I just used StructureMap few days ago. I use StructureMap for collecting all validator class like the following code. public class BaseClassA {} public class ClassB : BaseClassA {} public class ClassC : BaseClassB {} public BaseClassAValidator : IValidator<BaseClassA>() {} In StructureMap, I only register IValidator interface for B...

Why 'timeout expired' exception thrown with StructureMap?

I'm getting a the following exception: "Timeout Expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled conections were in use and max pool size was reached." ...from a relatively heavily trafficked ASP.NET MVC 2 site I developed using StructureMap and Fluent NHiber...

StructureMap: How can i unit test the registry class?

I have a registry class like this: public class StructureMapRegistry : Registry { public StructureMapRegistry() { For<IDateTimeProvider>().Singleton().Use<DateTimeProviderReturningDateTimeNow>(); } I want to test that the configuration is according to my intent, so i start writing a test: public class WhenConfigur...

How should I be using IoC in this winform piece of code?

Hi folks, I've got a winform app in visual studio 2010. My app does the following Get a list of files which I need to read the data then insert into a database. For each file, read data and insert into DB. So .. this is the code i have. // ******* // *** How should the _repository be Injected?? // ******* var list = _repository.Get...

Problems integrating nServiceBus with StructureMap

I'm trying to use StructureMap with nServiceBus. The Project: Uses a GenericHost Endpoint to send command messages Configures nServiceBus using the StructMapBuilder. Uses a simple StructureMap registry config Uses a start up class TestServer supporting IWantToRunAtStartup The TestServer class has ctor dependency on a TestManager clas...

How can I inject multiple repositories in a NServicebus message handler?

I use the following: public interface IRepository<T> { void Add(T entity); } public class Repository<T> { private readonly ISession session; public Repository(ISession session) { this.session = session; } public void Add(T entity) { session.Save(entity); } } public class SomeHandler : IHandleMessages<SomeMe...

WCF - StructureMap - Caching objects for the duration of the request only

So I already have a working implementation of StructureMap with the WCF service (including custom instance provider, behaviors, etc.) When I try to have an object that is instantiated only once per user request, I use the InstanceScope.HttpContext and it throws because the context is null. Do anyone have a proper way of doing that? ...

Why not lump all service classes into a Factory method (instead of injecting interfaces)?

We are building an ASP.NET project, and encapsulating all of our business logic in service classes. Some is in the domain objects, but generally those are rather anemic (due to the ORM we are using, that won't change). To better enable unit testing, we define interfaces for each service and utilize D.I.. E.g. here are a couple of the ...

Populate properties decorated with an attribute

Are there any frameworks that assist me with this: (thinking that perhaps StructureMap can help me) Whenever I create a new instance of "MyClass" or any other class that inherits from IMyInterface I want all properties decorated with [MyPropertyAttribute] to be populated with values from a database or some other data storage using the p...

Using ASP.NET MVC, Linq To SQL, and StructureMap causing DataContext to cache data

I'll start by telling my project setup: ASP.NET MVC 1.0 StructureMap 2.6.1 VB I've created a bootstrapper class shown here: Imports StructureMap Imports DCS.Data Imports DCS.Services Public Class BootStrapper Public Shared Sub ConfigureStructureMap() ObjectFactory.Initialize(AddressOf StructureMapRegistry) End Su...