# Register Service Modules

Parsley provides a convenient way to group related services into modules using the RegisterModule method. This method allows you to register a function that bundles service registrations, making your code more organized and maintainable. Here’s how to use it:

package main

import (
	"context"
	"github.com/matzefriedrich/parsley-docs/examples/registration-concepts/internal"
	"github.com/matzefriedrich/parsley/pkg/registration"
	"github.com/matzefriedrich/parsley/pkg/resolving"
	"github.com/matzefriedrich/parsley/pkg/types"
)

func main() {

	registry := registration.NewServiceRegistry()
	registry.RegisterModule(greeterModule)

	resolver := resolving.NewResolver(registry)
	greeter, _ := resolving.ResolveRequiredService[internal.Greeter](resolver, resolving.NewScopedContext(context.Background()))
	greeter.SayHello("John", false)
}

func greeterModule(registry types.ServiceRegistry) error {
	registry.Register(internal.NewGreeterFactory("Hi"), types.LifetimeTransient)
	return nil
}

# Benefits

Using RegisterModule offers several benefits. It helps maintain a clean and organized code structure by grouping related services, making the codebase more straightforward to manage.

Modules allow you to define and reuse service groupings across different parts of your application, promoting modularity and reusability. Additionally, this approach keeps the service registration logic separate from the application logic, enhancing the separation of concerns and improving overall code maintainability and clarity as your application scales.

Another use case could be a package that keeps all service implementation types private to the package but exports nothing else, like interfaces and module registration functions. This way, services can be integrated into apps without exposure.