pedrommuller
pedrommuller

Reputation: 16066

ServiceStack is IRequestLogger necessary?

In the service stack configuration I'm getting an error "No registration for type IRequestLogger could be found." with the default configuration, after looking around it looks that I need to add a a pluging like in the configuration.

Plugins.Add(new RequestLogsFeature { RequiredRoles = new string[] { } });

the question is why am I getting this error? and if necessary to define the IRequestLogger.

I'm using Simple Injector as the IoC Container.

Edit: this is my IoC Code:

 public override void Configure(Container container)
            { 

                var simpleInjector = new SimpleInjectorContainer();
                container.Adapter = simpleInjector;
                Plugins.Add(new RequestLogsFeature { RequiredRoles = new string[] { } });
                simpleInjector.SContainer.Register<ICacheClient, MemoryCacheClient>();
                simpleInjector.SContainer.Register<IUserRepository,UserRepository>();
                Routes.Add<UserRequest>("/Api/User/{Id}");

                //Routes.Add<HomeResponse>("/Api/Home","GET");

            }

     public class SimpleInjectorContainer:ISimpleInjectorContainer
        {

             public SimpleInjectorContainer()
             {
                 SContainer = new SimpleInjector.Container();
             }

             public SimpleInjector.Container SContainer { get; set; }

             public T TryResolve<T>()
             {

                 return (T)SContainer.GetInstance(typeof(T));
             }

             public T Resolve<T>()
             {
                 return (T)SContainer.GetInstance(typeof(T));
             }
        }

         public interface ISimpleInjectorContainer : IContainerAdapter
        {
             SimpleInjector.Container SContainer { get; set; }
        }

thanks.

Upvotes: 1

Views: 512

Answers (1)

kampsj
kampsj

Reputation: 3149

You need to make your TryResolve implementation more forgiving. It needs to be able to handle not being able to resolve the Service. If IRequestLogger resolves to null then ServiceStack will simply skip it.

Resolve should require the interface be registered. TryResolve should gracefully handle the interface not being registered.

See this SO answer for how to do this Prevent Simple Injector to throw an exception when resolving an unregistered service

Upvotes: 1

Related Questions