Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not resolve non-optional dependency

I have an interface like this:

public interface IdFactory
{
     Id Create(Guid userId);
}

and the Castle Windsor definition is like this:

container.Register(Castle.MicroKernel.Registration
    .Component.For<Id>().ImplementedBy<Id>().LifeStyle.Transient);

The calling code looks like this:

 var ID = IDFactory.Create(new Guid(userId));

The error I get is:

Castle.MicroKernel.Resolvers.DependencyResolverException: 'Could not resolve non-optional dependency for 'Id' (Id). Parameter 'id' type 'System.Guid''

What is the problem here? Do I have to configure System.Guid in Castle Windsor?

like image 424
w0051977 Avatar asked Sep 12 '25 09:09

w0051977


1 Answers

Parameter names of factory method and of class constructor being resolved must be the same:

public class Id
{
    public Id(Guid userId /*not - Guid id*/)
    {
    }
}
like image 101
Jan Muncinsky Avatar answered Sep 14 '25 00:09

Jan Muncinsky