I am in this situation where my service interface is being implemented by two service classes.
For example,
IFooService
is implemented by FooService
and FooWithExtraInfoService
Here is the interface:
public interface IFooService
{
Foo GetEntity(string fieldName, stringFieldValue);
}
Here is FooService
:
public class FooService: BarService, IFooService
{
public FooService(ILogService logservice): base(logservice)
{
}
public Foo GetEntity(string fieldName, string fieldValue)
{
//here goes the logic
}
}
Here is FooWithExtraInfoService
:
public class FooWithExtraInfoService: BarService, IFooService
{
public FooWithExtraInfoService(ILogService logservice): base(logservice)
{
}
public Foo GetEntity(string fieldName, string fieldValue)
{
//one possible option could be
var foo = new FooService(logservice).GetEntity(fieldName, fieldValue)
//do additional stuff
foo.SomeField = "abc";
}
}
As you can see one option could be creating new object of FooService and then telling unity to register type where IFooService
is implemented by FooWithExtraInfoService
.
Something like:
container.RegisterType<IFooService, FooWithExtraInfoService>();
But is there some other way where I don't have to create new object of FooService
?
//one possible option could be
var fooService = new FooService(logservice).GetEntity(fieldName, fieldValue)
//do additional stuff
And let Unity handle it somehow?
Or should I create different interface for FooWithExtraInfoService
?
I don't know what is the best way to approach this problem at this point.
Any suggestions would be helpful.