Quote from TeleportingBomb
I don't try this at all, building in generated structures. I seem to get attacked by a horde of zombies every time I try. So that means I have to defend the villagers, but then of course, the villagers open the door at first light, and that's long before zombies start to burn, so they get attacked and die, and a few turn into zombies themselves. Horrible, so I'm fighting my way out of the village until zombies burn, including the poor zombie villagers.
When the villagers go inside for the night, put blocks in front of the doors. Then you can put up a wall or fencing around the village. Once you have the village isolated from the mobs, then remove the blocks.