You could make this into a filter or a service and DI it into both of your factories.