What exactly is the difference between a Service
and a Component
? And how does the extension method RegisterComponent()
relate to this definitions?
Autofac's glossary defines it as follows:
Component
A body of code that declares the Services it provides and the Dependencies it consumes
Service
A well-defined behavioural contract shared between a providing and a consuming Component
This confuses me.. Would it be correct to say, that a component uses several services? Something like the example below?
public interface IServiceA
{
void DoSomething();
}
public ServiceA : IServiceA
{
void DoSomething()
{
// Do some magic
}
}
public class ComponentA
{
private readonly IServiceA serviceA;
public ComponentA(IServiceA serviceA)
{
this.serviceA = serviceA;
}
public void SomeOperation()
{
this.serviceA.DoSomething();
}
}
Or is a component always an implementation of a service/interface? I just don't get it.
I would be thankful if somebody could clarify with a catchable example.