I am creating new WCF service, on base of some old code. I think that I have done everything the same but during creating class using DI I get error:
Below is my new code that is done on basics of working one:
public SChangeClaimHandlerStatusDTO ChangeClaimHandler(SChangeClaimHandlerMessageDTO message)
{
(...)
var status =
ServiceProvider<Test.BusinessLayer.BusinessLogic.Order.S.SIntegrationService>
.Service.ChangeClaimHandler(message);
//line above is causing error
(...)
return status;
}
And below is called class:
public class SIntegrationService : ServiceBase
{
private const int SImageExpirationTimeInMinutes = 60;
public SIntegrationService(
IDocumentService documentService,
IAttachmentService attachmentService,
IUserService userService,
ITextEncryptor textEncryptor, (...) )
{
RegisterService<IDocumentService>(documentService);
RegisterService<IAttachmentService>(attachmentService);
RegisterService<IUserService>(userService);
RegisterService<ITextEncryptor>(textEncryptor);
(...)
}
}
public class ServiceBase : IBusinessService
{
public ServiceBase();
public ServiceBase(Dictionary<Type, object> dependencies);
protected IAppContext ApplicationContext { get; }
protected void RegisterService<T>(T dependency) where T : class;
}
And ServiceProvider class looking like this:
public class ServiceProvider<T> where T : class
{
public ServiceProvider();
public static T Service { get; }
}
class SIntegrationService has only one constructor (no parameterless constructor). Both programs have in references SimpleInjector.
I`m rather new to DI, so maybe I am missing something obvious, maybe i should put something into config file to let know that there will be DI included? I know that that should work in this way because I am staring on a code in other project that is workink fine.
In other project config I also have this line:
<Services
AutoWire="false"
IocContainer="V.Common.Ioc.SimpleInjector.SimpleInjectorContainerAdapter, V.Common.Ioc.SimpleInjector"/>
maybe thats the solution?
Below is error details:
System.MissingMethodException HResult=0x80131513
Message=No parameterless constructor defined for this object.
Source "mscorlib" string
StackTrace " at System.RuntimeTypeHandle.CreateInstance(RuntimeType >type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, >RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)\r\n
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)\r\n at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)\r\n at System.Activator.CreateInstance(Type type, Boolean nonPublic)\r\n at System.Activator.CreateInstance(Type type)\r\n
at V.Common.Services.ServiceProvider`1.get_Service()\r\n at BusinessServices.SIntegration.SIntegrationService.ChangeClaimHandler(SChangeClaimHandlerMessageDTO message) in D:\TFS1\Branches\Release 1.2.1 Env01\ZV\BusinessServices.SIntegration\SOrderService.svc.cs:line 31\r\n at SyncInvokeChangeClaimHandler(Object , Object[] , Object[] )\r\n at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)\r\n at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)" string
User contributions licensed under CC BY-SA 3.0