Matt,

First of all inspect what the cycle is, and why it appears. Can you break it?

If not, think about what would you do differently if you were building the graph by hand.

If you then can share those details we will be able to assist you further.

cheers,
Krzysztof

On 21/12/2011 10:38 PM, Matt wrote:
Hi,

I'm struggling to resolve a circular dependency issue.  I'm using
Castle to resolve view models in an MVVM project and some view models
have a child parent relationship.  All my view models inherit from
ViewModelBase.

I have a factory interface:

public interface IViewModelFactory
{
         T CreateViewModel<T>() where T : ViewModelBase;
         T CreateViewModel<T>(ViewModelBase parentModel) where T :
ViewModelBase;
}

I have a basic installer which simply registers the factory interface
and also all types based on ViewModelBase

Every time I try to call something like

var commands =
factory.CreateViewModel<TemplateCommandsViewModel>(this);

I get a circular dependency exception.

However when I stripped the code down to purely the IOC stuff and
moved it to a different project it works fine.

When I watch the constructors in the debugger, instead of passing
"this" through to the constructor, a new instance is created.

Being relatively new to Castle, I am absolutely clueless as to where
to start on this one.  Any ideas?

Thanks,

Matt


--
You received this message because you are subscribed to the Google Groups "Castle 
Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to