ardalis / ardalis/CastleWindsorSample
interfaces and implementation in different namespaces or in different projects
- Dominant language
- C#
- Stars
- 3
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Great example.
Can you please show how can we register for scenario where interfaces and classes are in different namespaces. Like in below example I have created 2 different namespaces and separated interfaces and classes. And now if I try to register with that approach you have mentioned in the Program, it fails with error No Component found.
I also tried changing namespace name in parameter of InNamespace method but no luck.
Actually in my case, interfaces and implementations are in different projects (assembly). It would be great if you could show how it can be achieved in such case.
```
namespace CastleWindsorConsole.Interfaces
{
public interface IGreeting
{
string Greet(string name);
}
public interface IWriter
{
void WriteLine(string message);
}
public class HelloGreeting : IGreeting
{
public string Greet(string name)
{
return String.Format("Hello, {0}", name);
}
}
}
namespace CastleWindsorConsole.ImplementedClasses
{
public class ConsoleWriter : Interfaces.IWriter
{
Interfaces.IGreeting greeting;
public ConsoleWriter(Interfaces.IGreeting greeting)
{
this.greeting = greeting;
}
public void WriteLine(string message)
{
greeting.Greet(message);
Console.WriteLine(message);
}
}
public class Greeter
{
private readonly Interfaces.IGreeting _greeting;
private readonly Interfaces.IWriter _writer;
public Greeter(Interfaces.IGreeting greeting, Interfaces.IWriter writer)
{
Name = "Unknown Greeter";
_greeting = greeting;
_writer = writer;
}
public string Name { get; set; }
public void Execute(string personToGreet)
{
_writer.WriteLine("Executing for Greeter " + Name);
_writer.WriteLine(_greeting.Greet(personToGreet));
}
}
}
```
Thanks
Contributor guide
No contributing guide indexed for this repository
Research direction
Start from the registration approach in Program and reproduce the reported setup with the interfaces and implementations in the two namespaces or projects shown in the issue. Done means the sample demonstrates registration and resolution without the “No Component found” error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100