I am familiar with Ninject and in Ninject you can do something similar to
Bind<ICalendar>().To<MonthCalendar>().WhenInjectedInto(typeof(Roster)).InRequestScope();
I'm not sure how to perform something similar in StructureMap. I need to be able to do this dynamically from my own binding without the use of the generic StructureMap metho...
How to do Dependency Injection on Property of a class Using Structure Map
public class ContactController : Controller
{
public IContactService Service { get; set; }
public ContactController()
: this(null,null)
{
}
[SetterProperty]
public MembershipProvider Provider { get; private set; }
}
Here when i ...
I have the Seam session-scoped component, CustomIdentity which overrides the standard Seam Identity (also session-scoped). The extended CustomIdentity has a property
@Out(required=false, scope=ScopeType.SESSION)private User user
In the overriden login() I define a User object, populated with information from the Principal of the Http...
So lets say i have this code
var builder = new ContainerBuilder();
builder.RegisterInstance(new MyType());
var container = builder.Build();
Then some time later I want to change the instance of MyType for all future resolves that are called on container.
...
So I have two separate views in a WPF Prism app. How can I inject the same instance of a viewmodel into both the views via Depencency Injection?
...
I am building a framework that I don't want to couple to a particular IOC container so have created a layer on top of Ninject / structuremap etc.
I have a binding class that accepts a Func to allow binding to a method.
For example
public class Binding
{
public Type Source { get; set; }
public Func<object> Method {get; set; }
public...
Hi all,
I was wondering if there is already a book available, more or less dedicated to CDI (Contexts and dependency injection - JSR299).
Dependency Injection by Dhanji Prasanna is a good book, but it more focussed on JSR330 and Spring DI.
Thank you,
J.
...
hi,
I am creating a new application using asp.net mvc, I m using munq IOC container as my dependency injection..The issue is i want to create a new project for dependency resolution where i can register all the controllers of mvc project and the repositories of infrastructure project..I have to add Dependency Resolution project as a refe...
Dependency injection looks great, however when I look at examples I often see lots of XML config file. This is not good because:
I don’t get compile time checking on the type names in the config files
Refactoring tools don’t update the confilg files when types are renamed
I don’t want the customers changing the configuration!
I am a ...
Does Castle Windsor support applying setter injection to existing service instances? I have a case in which I have no control over the creation of certain class instances while I do need to resolve dependencies for them. This rules out constructor injection but leaves the door open for setter injection since I can intercept the new insta...
Hi!
I am building an module for an application that is based on MVVM, CAL and PRISM. I'm fairly new to these concepts, and trying to get my head around all the patterns and right now I'm struggling with the following problem:
I am in the need of creating multiple instances of the same View. Each one of the views need to bind to it's o...
I have a readonly .NET property exposed from a managed wrapper which gets the name of the database, let's say the property name is DBName. The DBName may vary depending upon the database connected to the WPF application. This property getter and setter also resides inside the managed .NET wrapper. I am using this(DBName) property in my...
Hi,
I'm trying to instantiate a generic class in Spring, but I get following exception:
Initialization of bean failed; nested exception is
org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class football.dao.jpa.GenericJpaDAO]: Common causes of this problem include using a final cla...
I am working with several Spring MVC web applications and I use the getter/setter dependency injection and configure all my beans in my app-servlet.xml file.
I believe that I am following convention with most of the properties and beans that I am injecting into my controller beans such as my DAO's and other beans that I have specified i...
I consider myself an experienced programmer and understand the basic concept of dependency injection. On the other hand, most of my experience is in writing relatively low-level, one-man number crunching code. I have no experience whatsoever working on large enterprise projects.
Given this background, I can't for the life of me wrap m...
Hi,
I would like to have a Bean and a SubBean like this:
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Component
public class SubBean implements ApplicationContextAware{
private Object parent;
public void setApplicationContext(ApplicationContext ctx){
this.parent = doSomeMagicToGetMyParent(ctx);
}
public Object getParent(){
...
I have a service class :
public class MyService : IService
{
private IRepoA repoA;
private IRepoB repoB;
public MyService(IRepoA repoA,IRepoB repoB)
{
this.repoA=repoA;
this.repoB=repoB;
}
}
my Controller depends on the MyService classL
public MyController : DefaultController
{
IService myServ...
If I have the following setup, how can I configure my container to use the same database, when objects are created in the same context
public class Database { }
public interface IRepository { Database Database { get; } }
public interface IFooRepository : IRepository { }
public interface IBarRepository : IRepository { }
public class Foo...
There's something I just don't get about guice: According to what I've read so far, I'm supposed to use the Injector only in my bootstrapping class (in a standalone application this would typically be in the main() method), like in the example below (taken from the guice documentation):
public static void main(String[] args) {
/*
...
I'm using MVVM light and have set up the binding as following:
class TestModule:NinjectModule
{
public override void Load()
{
Bind<ICollection<Element>>().To<Collection<Element>>();
Bind<Element>().ToSelf();
}
}
When I try to get a ICollection I get a collection with ONE element. I expect an exmpty collecti...