public ServiceDefinitionBuilder Service(Type implementationType)
        {
            var existingServiceDefinition = Model.FindServiceByImplementation(implementationType);

            if (existingServiceDefinition != null)
            {
                if (existingServiceDefinition.Type != ServiceType.Local)
                {
                    throw new InvalidOperationException($"The service '{existingServiceDefinition.Name}' is already defined as '{existingServiceDefinition.Type}' and should not be re-defined as '{ServiceType.Local}'. Use a different builder method.");
                }
                return(new ServiceDefinitionBuilder((IMutableServiceDefinition)existingServiceDefinition));
            }

            var serviceDefinition = new ServiceDefinition((CommunicationModel)Model);

            serviceDefinition.Type           = ServiceType.Local;
            serviceDefinition.Implementation = implementationType;

            var generatedServiceName = DefaultServiceNamer.GetServiceNameFromType(implementationType);

            if (Model.FindServiceByName(generatedServiceName) == null)
            {
                serviceDefinition.Name = generatedServiceName;
            }

            var defaultInterfaceType = DefaultServiceInterfaceFinder.FindDefaultInterface(implementationType);

            if (defaultInterfaceType != null && Model.FindServiceByInterface(defaultInterfaceType) == null)
            {
                serviceDefinition.AddInterface(defaultInterfaceType);
            }

            return(ServiceDefinitionBuilder.CreateByImplementationType(implementationType, serviceDefinition));
        }
        public static Type FindDefaultInterface(Type serviceType)
        {
            var generatedServiceNameFromImplementation = DefaultServiceNamer.GetServiceNameFromType(serviceType);

            foreach (var interfaceType in serviceType.GetInterfaces())
            {
                var generatedServiceNameFromInterface = DefaultServiceNamer.GetServiceNameFromType(interfaceType);
                if (generatedServiceNameFromImplementation == generatedServiceNameFromInterface)
                {
                    return(interfaceType);
                }
            }

            return(null);
        }