structuremap

StructureMap Plugins - easier way?

Let's say you have an interface of IModel that takes a pair of generics ... public interface IModel<TOne, TTwo> { TOne ConvertToOne(TTwo two); TTwo ConvertToTwo(TOne one); } and a class that implements this public class OneTwo : IModel<SomethingOne, SomethingTwo> { SomethingOne ConvertToOne(SomethingTwo two) { //zomg!...

Is Structuremap singleton thread safe?

Hi, Currently I have the following class: public class PluginManager { private static bool s_initialized; private static object s_lock = new object(); public static void Initialize() { if (!s_initialized) { lock (s_lock) { if (!s_initialized) { // initialize ...

StructureMap resolve dependency through injection instead of service location

In my project I register many ISerializers implementations with the assembly scanner. FWIW this is the code that registers my ISerializers Scan(scanner => { scanner.AssemblyContainingType<ISerializer>(); scanner.AddAllTypesOf<ISerializer>().NameBy(type => type.Name); scanner.WithDefaultConventions(); }); Which then correct...

StructureMap: How to register the same instance for all its interfaces

StructureMap newbie question. public class SomeClass: IInterface1, IInterface2 { } I would like the following test to pass: Assert.AreSameInstance( container.GetInstance<IInterface1>(), container.GetInstance<IInterface2>()); How would I do an explicit registration of this? I know in Castle Windsor I would do something lik...

Approaches to use Repositories (w/ StructureMap) with AutoMapper?

Any idea how I can tell AutoMapper to resolve a TypeConverter constructor argument using StructureMap? ie. We have this: private class StringIdToContentProviderConverter : TypeConverter<string, ContentProvider> { private readonly IContentProviderRepository _repository; public StringIdToContentProviderConverter(ICon...

StructureMap partitioning?

I have a set of applications that all use the same basic codebase -- a couple of ASP.NET web projects, some WCF services (running under ASP.NET), a few Windows services and a couple of executables. Most of them are even located in a single Visual Studio solution. There's a lot of duplication between the various applications as far as...

Using StructureMap to create classes by a name?

How can I use StructureMap to resolve to an appropriate implementation of an interface based on a name stored in an attribute? In my project, I have many different kinds of widgets, each descending from IWidget, and each decorated with an attribute specifying the kind of associated element. To illustrate: [Configuration("header")] pub...

Auto wiring of Property does not work for me

Hi All, In my Asp.Net project I wanna use Property Auto-wiring, e.g. for my ILogger. Basically I placed it as Property into class where I need to use it. Like below. public class UserControlBase : UserControl { public ILogger CLogger { get; set; } .... } public partial class IPTracking : UserControlBase { protected void Pa...

How to verify StructureMap is disposing of objects properly

I'm currently using StructureMap to inject instances of NHibernate ISessions using the following code: ObjectFactory.Initialize(x => { x.ForRequestedType<ISession>() .CacheBy(InstanceScope.PerRequest) .TheDefault.Is.ConstructedBy(y => NHibernateSessionManager.Instance.GetSession()); }); I'm assuming that the Ca...

StructureMap with my own attributes in C#

Hi All, I have an attribute that I have written that has a dependency on the Data Access Layer so I made a constructor that took the DAL class as a parameter (marked with [DefaultConstructor] and another, blank, constructor that is parameterless. When I call a method that depends on the attribute how do I make StructureMap inject the co...

Checking whether an object exists in StructureMap container

I'm using StructureMap to handle the creation of NHibernate's ISessionFactory and ISession. I've scoped ISessionFactory as a singleton so that it's only created once for my web app and I've scoped ISession as a hybrid so that it will only be opened once per web request. I want to make sure that at the end of each web request, I pro...

StructureMap: "No default instance of plugin defined" - even though it is

I've been using StructureMap for about 6 months now; you would think it would start getting easier. It doesn't seem to. Here's the first line of my registry: For<IDbConnection>() .Singleton() .Use<SqlConnection>() .Ctor<string>(WebConfigurationManager.ConnectionStrings["UnifiedConnection...

Can not find StructureMapConfiguration object

I see a lot of exampls of how to use StructureMap in a asp.net project like this: StructureMapConfiguration.ForRequestedType<IResourceA>() .TheDefaultIsConcreteType<ResourceB>() .CacheBy(InstanceScope.Singleton); Yet, in my Global.asax I can not access the StructureMapConfiguration object even when I import the StructureMap na...

How to manage interface segregation when using an IoC container?

I'm currently designing a small system and i'm currently using structureMap as IoC. I just recently got the point of interface segregation...and I'm wondering now. If I have a certain business object, that will implement say, three interfaces... how should I handle this in the configuration and instatiation of code? Assuming I have two...

StructureMap List of Non primitive types

I am trying to figure out how to setup StructureMap (using an XML Configuration file). One class has a constructor with a list containing instances of a 2nd class: public interface ITestDocType { } class TestDocType : ITestDocType { public List<AttributeRef> AttrRefs { get; set; } public TestDocType(List<AttributeRef> attrRefs...

Handling dependencies with IoC that change within a single function call

We are trying to figure out how to setup Dependency Injection for situations where service classes can have different dependencies based on how they are used. In our specific case, we have a web app where 95% of the time the connection string is the same for the entire Request (this is a web application), but sometimes it can change. ...

StructureMap - Scan - Generic Interface with base implementation and specific.

Hi I have an interface something like this: interface IGenericSetupViewModel<T> I then have a default implemtation of this, something like this class GenericSetupViewModel<T> : IGenericSetupViewModel<T> For some specific classes i have a specific implementation like this: class ContractSetupViewModel : GenericSetupViewModel<Contr...

Design help for service and repository layers

I've been running into some problems with my design. Here is what I have now... Controller ... <AcceptVerbs(HttpVerbs.Post)> _ Public Function Edit(ByVal id As Integer, ByVal dryShots As Integer, ByVal clock As Integer) As ActionResult Dim job As Shift_Summary_Job = _shiftSummaryJobService.GetShiftSummaryJob(id) _shiftSummaryJ...

StructureMap remove all disposed object references but leave configuration

Hy guys, I am currently trying to implement some custom ILifecycles for StructureMap. Depending on events the lifecycle is associated with all object should be removed from the lifecycle. Here is the registration for an object. I get a lifecycle from my manager for a plugintype and concretetype using a scope to determine the lifecycle....

Structuremap and generic types

Hi I have a situation which seems a bit different from others I've seen. For clarrification, this isn't the normal question eg; something like IAClass maps to AClass etc - that involves using basically a single concrete classes per interface. This involves having a single generic class, but I want to be able to load ALL possible usage...