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!...
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
...
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 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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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.
...
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...
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...
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....
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...