def explode(self, hosts, hostgroups, contactgroups, servicegroups, servicedependencies):
        itemkeys = list(self.items.keys())
        for s_id in itemkeys:
            serv = self.items[s_id]
            self.explode_host_groups_into_hosts(serv, hosts, hostgroups)
            self.explode_contact_groups_into_contacts(serv, contactgroups)
            hnames = getattr(serv, "host_name", '')
            hnames = list(set([n.strip() for n in hnames.split(',') if n.strip()]))
            if len(hnames) == 1:
                self.index_item(serv)
            else:
                if len(hnames) >= 2:
                    self.explode_services_from_hosts(hosts, serv, hnames)
                self.remove_item(serv)
        for s_id in self.templates:
            template = self.templates[s_id]
            self.explode_contact_groups_into_contacts(template, contactgroups)
            self.explode_services_from_templates(hosts, template)
        duplicates = [serv.uuid for serv in self if getattr(serv, 'duplicate_foreach', '')]
        for s_id in duplicates:
            serv = self.items[s_id]
            self.explode_services_duplicates(hosts, serv)
            if not serv.configuration_errors:
                self.remove_item(serv)
        to_remove = []
        for service in self:
            host = hosts.find_by_name(service.host_name)
            if host and host.is_excluded_for(service):
                to_remove.append(service)
        for service in to_remove:
            self.remove_item(service)
        for serv in self:
            self.register_service_into_servicegroups(serv, servicegroups)
            self.register_service_dependencies(serv, servicedependencies)