Hi Everyone.
I’m very new to NHibernate, Fluent & S#arp but i’m very keen to learn and have an idea of how OOP and DDD works.
One question I have though is if it’s possible to some way extend the IRepositry class, at the moment it provides some basic CRUD functions such as Get, GetAll etc...
However, for this project I am creating for virtually every call to the database i need to pass a SiteId to filter the data, i thought it would be easier to extend the IRepositroy class itself rather than creating 15-20 interfaces which inherit the IRepository class (like the Northwind example project has done for a couple of classes) and add my own functions.
Also, i would like to include a function to page data results, so instead of GetAll, you would have GetAllPaged(pageIndex, numPerPage) so all classes which inherit the IRepositry interface can use these functions.
Sorry if any of my terminology is incorrect, hope you understand what i mean!
Regards,
Paul Hinett
w: http://www.ukcreativedesigns.com | e: pa...@ukcreativedesigns.com | t: 07958 552 157
Hi,
Thanks for the replies so far, the reason I need to pass SiteId to most calls is because my application will run several versions of the website for multiple domains.
At the moment I have 2 domains (house-mixes.com & urban-mixes.com). Both sites work identically but contain it’s own set of members and member data such as music, profiles, messages etc...
So when i need to return data from the database such as a list of members, dj mixes, genres etc i need to pass a SiteId to filter the data.
Having thought about it a little i may just create my own custom repositories for this data and be done with it, am I right in thinking this?
Thank You!
Paul
Is there any data that is shared between the sites.
If not it sounds like you would be better off with separate databases.
Thank you very much guys, mult-tanant architecture is new terminology to me and is exactly what i am looking for!
When you say i may need to make some slight customisations of S#arp, do you mean i will need to modify the S#arp source code?
Thanks for all the help on this matter so far!
Hi,
I’ve had a good read through lots of information about Multi-Tenancy on the web, Ayende’s articles were very good and offered some very good advice which I want to follow.
I have downloaded the sample application created by him, the MultiTenancy.Web application. I think i understand what’s going on here, however I can’t get my head around how I would split this project up into different layers, such as my Core project, data project etc from the code he has provided, the code is also based around standard NHibernate and doesn’t use multi-tier architecture which is throwing me off understanding.
The sample application is using xml configuration files for NH, and includes a Model folder inside the multiple MVC projects for different tenants, obviously this isn’t what i want to do in s#arp.
I am probably asking for quite a lot of help in one topic her, but i’m not sure how i can break my questions down?
This is probably one of the main files which i am stuck with at the moment:
public abstract class AbstractBootStrapper : IBootStrapper
{
private IWindsorContainer container;
public RootContext RootContext { get; private set; }
public abstract string TenantId { get; }
protected virtual Assembly Assembly
{
get { return GetType().Assembly; }
}
#region IBootStrapper Members
public void Init(RootContext context)
{
RootContext = context;
}
public TenantContext CreateContext()
{
container = CreateContainer();
ConfigureContainer();
ConfigureNHibernate();
return new TenantContext(container, Assembly.GetName().Name);
}
#endregion
protected virtual void ConfigureNHibernate()
{
var configuration = new Configuration()
.SetProperties(new Dictionary<string, string>
{
{Environment.Dialect, typeof (MsSql2005Dialect).AssemblyQualifiedName},
{Environment.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName},
{Environment.ConnectionString, RootContext.GetConnectionStringFor(TenantId)},
});
var customMapping = GetMappingFrom(Assembly);
var added = new HashSet<string>();
foreach (var mapping in customMapping)
{
configuration.AddResource(mapping, Assembly);
added.Add(GetEntityName(mapping));
}
var coreMapping = GetMappingFrom(typeof(AbstractBootStrapper).Assembly);
foreach (var mapping in coreMapping)
{
if (added.Add(GetEntityName(mapping)) == false)
continue;//already there
configuration.AddResource(mapping, typeof (AbstractBootStrapper).Assembly);
}
container.Kernel.AddComponentInstance<Configuration>(configuration);
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
//wasNHibernateInitialized = true;
var updater = new SchemaUpdate(configuration);
updater.Execute(false, true);
container.Kernel.AddComponentInstance<ISessionFactory>(sessionFactory);
}
private string GetEntityName(string mapping)
{
var replace = mapping.Replace(".hbm.xml", "");
var namespaceEnd = replace.IndexOf("Model.");
return replace.Substring(namespaceEnd);
}
private static IEnumerable<string> GetMappingFrom(Assembly assembly)
{
return from mapping in assembly.GetManifestResourceNames()
where mapping.EndsWith(".hbm.xml")
select mapping;
}
protected virtual void ConfigureContainer()
{
container.Register(
AllTypes.Of<IController>()
.FromAssembly(Assembly)
.Configure(registration =>
{
var name = registration.Implementation.Name;
registration.Named(name.Replace("Controller", "").ToLowerInvariant());
}),
AllTypes.Of<IController>()
.FromAssembly(typeof(AbstractBootStrapper).Assembly)
.Configure(registration =>
{
var name = registration.Implementation.Name;
registration.Named(name.Replace("Controller", "").ToLowerInvariant());
}),
AllTypes.FromAssembly(Assembly)
.Where(x=>x.Namespace.EndsWith("Services"))
.WithService.FirstInterface(),
AllTypes.FromAssembly(typeof(AbstractBootStrapper).Assembly)
.Where(x=>x.Namespace.EndsWith("Services"))
.WithService.FirstInterface()
);
}
protected virtual WindsorContainer CreateContainer()
{
return new WindsorContainer();
}
}
If anybody has this project downloaded or has any experience with it I would be extremely greatful if you could point me in the right direction, as soon as i have got my claws into it and grasp what is going on I should be fine.
Thank you very much!
Paul
I have had a good go at looking through various source codes today which deal with Multi-Tenancy and NHibernate but can’t work out what steps to take to achieve my goal with S#arp.
This is what i want to achieve:
1) Have a Main website with all the normal S#arp projects (core, data, web etc), this uses it’s own database as normal.
2) Have other tenant websites which extend the main website the way that Ayende described, i’m assuming i also want other tenant to have their own projects (core, data, web etc which inherit the main websites classes if i want to expand on them).
3) At the moment in my global.asax i am calling the SchemeUpdate method to make any required changes to the DB, how can I do this to update both databases for both tenants.
I am a real newbie when it comes to dependency injection, reflection and S#arp so it’s a big learning curve for me and I think you guys are probably the best to be talking to as you seem extremely helpful!
Could someone provide some pseudo code or even a skeleton project which shows how to achieve this? It’s probably asking too much i know but thought i would ask anyway.
I have looked at several projects which utilise some of these technologies and I mostly understand them, but they don’t keep each layer separate, such as the models and controllers are all part of the MVC app.
Thank you guys!
Paul
Hi Bobby,
That is fantastic!! I have been working on this all night and this is going to be a HUGE help I can’t thank you enough for your time and help!
One question I have though is how can I extend this to support a custom view per tenant and possibly extending the Order Repository per tenant? When reading through Ayende’s blog about this topic he advises to use different projects per tenant and add references to the core project, would this be possible or can it all be done within the same project?
Realistically I am only every going to have between 2-10 tenants.
Thanks Bobby!
Hi Bobby,
Just thought i would let you know that your comments aren’t working on your blog, i posted up a comment the other day but just realised it’s not there.
Keep up the good work!