new method for "withFactory" definitions and for "withOption". A lot of refactoring